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?

Recommended Answers

what can be change number to letter? I don't really understand what you're asking here

Jump to Post

All 2 Replies

what can be change number to letter? I don't really understand what you're asking here

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.