Question
Compile and run below program. Make sure to click on the Output Window. Test the program by entering different characters. Take notes of below program
-
Compile and run below program.
-
Make sure to click on the Output Window.
-
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.
-
Submit your work.
The international standard letter/number mapping found on the telephone is shown below:
|
I need notes at the end of the lines of code in Java. For example : import java.util.Scanner; //importing Java Scanner library
// 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started