title: Converting all letters in the phone number to digits
body: <p>Im trying to replace each letter with a digit using the international standard letter/number mapping. I got my output to run correctly however, how do get the dashes in the phone number to appear automatically in the output? For example, if I enter 1800Flowers it prints out as 18003569377. How do I get it to print out as 1-800-3569377 without using regular expressions?</p>
  
  <pre><code>import java.util.Scanner;
  
  public class PhoneKeypad {
  
  public static void main(String[] args) {
  
      Scanner input = new Scanner(System.in);
  
      //while loop keeps the program running until the user enters quit 
      while (true) {
          System.out.println("\nEnter a phone number or quit to exit:");
          String phoneNumber = input.next();
  
          if (phoneNumber.equalsIgnoreCase("quit")) {              
              System.out.print("\nProgrammed by me");
              return;
          }
  
          //checks if the phone number entered is at least 8 digits
          if (phoneNumber.length() &lt; 8) {
              System.out.println("Invalid Phone Number");
  
          } else {
  
              System.out.println(getNumber(phoneNumber));
          }
      }
  
  }
  
  //method converts all letters in the phone number to digits
  public static String getNumber(String phoneNumber) {
  
      int keypadNum = 0;
  
      for (int i = 0; i &lt; phoneNumber.length(); i++) {
          char letter = phoneNumber.charAt(i);
  
          if (Character.isAlphabetic(letter)) {
              letter = Character.toUpperCase(letter);
  
              switch (letter) {
                  case 'A':
                  case 'B':
                  case 'C':
                      keypadNum = 2;
                      break;
                  case 'D':
                  case 'E':
                  case 'F':
                      keypadNum = 3;
                      break;
                  case 'G':
                  case 'H':
                  case 'I':
                      keypadNum = 4;
                      break;
                  case 'J':
                  case 'K':
                  case 'L':
                      keypadNum = 5;
                      break;
                  case 'M':
                  case 'N':
                  case 'O':
                      keypadNum = 6;
                      break;
                  case 'P':
                  case 'Q':
                  case 'R':
                  case 'S':
                      keypadNum = 7;
                      break;
                  case 'T':
                  case 'U':
                  case 'V':
                      keypadNum = 8;
                      break;
                  case 'W':
                  case 'X':
                  case 'Y':
                  case 'Z':
                      keypadNum = 9;
                      break;
                  default:
                      System.out.println("Invalid phone number");
              }
  
              phoneNumber = phoneNumber.substring(0, i) + keypadNum + phoneNumber.substring(i + 1);
          }
      }
  
      return phoneNumber;
  }
  }
  </code></pre>
  
  <p>Expected Output:
  <a href="https://i.stack.imgur.com/aEQXc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aEQXc.png" alt="Output"></a></p>