0
import java.util.*;
public class scwhile{

	static Scanner input = new Scanner (System.in);
    public static void main (String[] args)    {
	
		char letter;                                     
        String inputMessage;
        String inputString;
        String outputMessage;
        
        inputMessage = "Program to convert uppercase " + "letters to their corresponding "+ "telephone digits.\n"
                     + "To stop the program enter #.\n"
                     + "Enter a letter:";
        	
        	System.out.println(inputMessage); 
        	letter = input.next().charAt(0);                  
				while (letter != '#' ) {
			    outputMessage = "The letter you entered is: " + letter + "\n"
			    	            + "The corresponding telephone " + "digit is: ";
        			if (letter >= 'A' && letter <= 'Z'){
        				switch (letter){
        					case 'A':
        					case 'B':
        					case 'C':
        					outputMessage = outputMessage+ "2";
        				break;
        					case 'D':
        					case 'E':
        					case 'F':
        					outputMessage = outputMessage+ "3";
        			 	break;
        			 		case 'G':
        			 		case 'H':
        			 		case 'I':
        			 		outputMessage = outputMessage+ "4";
        			 	break;
        			 		case 'J':
        			 		case 'K':
        			 		case 'L':
        			 		outputMessage = outputMessage+ "5";
        			 	break; 
        			 		case 'M':
        			 		case 'N':
        			 		case 'O':
        			 		outputMessage = outputMessage+ "6";
        			 	break;
        			 		case 'P':
        			 		case 'Q':
        			 		case 'R':
        			 		case 'S':
        			 		outputMessage = outputMessage + "7";
        			 	break;
        			 	   	case 'T':
        			 	   	case 'U':
        			 	   	case 'V':
        			 	   	outputMessage = outputMessage+ "8";
        			 	break;
        			 		case 'W':
        			 		case 'X':
        			 		case 'Y':
        			 		case 'Z':
        			 		outputMessage = outputMessage+ "9";}
        			 		
        		        }            
        		        else
        		        	outputMessage = outputMessage + "Invalid input";
		    				System.out.println(outputMessage);
		    				inputMessage = "Enter another uppercase letter " + "to find its corresponding " + "telephone digit.\n"
		    	                         + "To stop the program enter #.\n"
		    	                         + "Enter a letter:";
		    	            	
		    	            	System.out.println (inputMessage);
		    	            	letter = input.next().charAt(0);
		    	            	
		  				}//end while
		  		}
		}

ahmm.... it can be change number to letter?? can u help me to change it?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

Do you mean you want it to do the reverse translation, eg you enter "2" and it replies "ABC"? If so that's exactly the same structure as the program you already have; you just need to change the constants inside the switch, plus a couple of if tests.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.