Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class phonenumberconverter
  4. {
  5.    public static void main(String[] args)
  6.    {
  7.       String input, output = "";
  8.       char c;
  9.       int ctr;
  10.      
  11.       input = JOptionPane.showInputDialog("Enter a ten character alphanumeric phone number as such: XXX-XXX-XXXX");
  12.      
  13.       for (ctr = 0; ctr < 12; ctr++)
  14.       {
  15.          c = input.charAt(ctr);
  16.          
  17.          if(Character.isLowerCase(c))
  18.          {
  19.             c =  Character.toUpperCase(c);
  20.          }
  21.          
  22.          switch(c)
  23.          {
  24.             case '-':                                         output+="-"; break;
  25.             case '9':                                         output+="9"; break;
  26.             case '1':                                         output+="1"; break;
  27.             case '2': case 'A': case 'B': case 'C':           output+="2"; break;
  28.             case '3': case 'D': case 'E': case 'F':           output+="3"; break;
  29.             case '4': case 'G': case 'H': case 'I':           output+="4"; break;
  30.             case '5': case 'J': case 'K': case 'L':           output+="5"; break;
  31.             case '6': case 'M': case 'N': case 'O':           output+="6"; break;
  32.             case '7': case 'P': case 'Q': case 'R': case 'S': output+="7"; break;
  33.             case '8': case 'T': case 'U': case 'V':           output+="8"; break;
  34.             case '0': case 'W': case 'X': case 'Y': case 'Z': output+="0"; break;
  35.          }
  36.          
  37.          //ctr++;
  38.       }
  39.      
  40.       JOptionPane.showMessageDialog(null, output);
  41.    }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement