Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class phonenumberconverter
- {
- public static void main(String[] args)
- {
- String input, output = "";
- char c;
- int ctr;
- input = JOptionPane.showInputDialog("Enter a ten character alphanumeric phone number as such: XXX-XXX-XXXX");
- for (ctr = 0; ctr < 12; ctr++)
- {
- c = input.charAt(ctr);
- if(Character.isLowerCase(c))
- {
- c = Character.toUpperCase(c);
- }
- switch(c)
- {
- case '-': output+="-"; break;
- case '9': output+="9"; break;
- case '1': output+="1"; break;
- case '2': case 'A': case 'B': case 'C': output+="2"; break;
- case '3': case 'D': case 'E': case 'F': output+="3"; break;
- case '4': case 'G': case 'H': case 'I': output+="4"; break;
- case '5': case 'J': case 'K': case 'L': output+="5"; break;
- case '6': case 'M': case 'N': case 'O': output+="6"; break;
- case '7': case 'P': case 'Q': case 'R': case 'S': output+="7"; break;
- case '8': case 'T': case 'U': case 'V': output+="8"; break;
- case '0': case 'W': case 'X': case 'Y': case 'Z': output+="0"; break;
- }
- //ctr++;
- }
- JOptionPane.showMessageDialog(null, output);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement