Question: Compile and run below program in Java . Make sure to click on the Output Window. Test the program by entering different characters. Take notes

  1. Compile and run below program in Java.

  2. Make sure to click on the Output Window.

  3. Test the program by entering different characters. Take notes of below program and your observations and include in your comments:

  • Note toUpperCase()method converting the input to upper case letters.

  • Note if the user input more than one letter, note what charAt(0)do.

  1. Submit your work.

    The international standard letter/number mapping found on the telephone is shown below:

1

2 ABC

3 DEF

4 GHI

5 JKL

6 MNO

7 PQRS

8 TUV

9 WXYZ

0

The following program reads a letter and displays its corresponding digit.

// Program # 1

import java.util.Scanner;

public class Program1 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter a letter: ");

char ch = input.nextLine().charAt(0);

int number = 0;

switch (Character.toUpperCase(ch))

{

case 'A':

case 'B':

case 'C': number = 2; break;

case 'D':

case 'E':

case 'F': number = 3; break;

case 'G':

case 'H':

case 'I': number = 4; break;

case 'J':

case 'K':

case 'L': number = 5; break;

case 'M':

case 'N':

case 'O': number = 6; break;

case 'P':

case 'Q':

case 'R':

case 'S': number = 7; break;

case 'T':

case 'U':

case 'V': number = 8; break;

case 'W':

case 'X':

case 'Y':

case 'Z': number = 9; break;

default: System.out.println(ch + "is an invalid input ");

System.exit(1);

}

System.out.println("The corresponding number is " + number);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!