1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rudiy27
3 years ago
7

Write a program that prompts the user to enter a letter and displays its corresponding

Computers and Technology
1 answer:
pochemuha3 years ago
7 0

Answer:

The program to this question can be given as:

Program:

import java.util.*;  //import package.

public class Main      //define class  

{

public static int convert_Number(char ch_Ar) //decalre function.

{

//conditional statement.

//check condition with OR operator

if(ch_Ar == 'A' || ch_Ar == 'B'|| ch_Ar == 'C')

return 2;

else if(ch_Ar == 'D' || ch_Ar == 'E'|| ch_Ar == 'F')

return 3;

else if(ch_Ar == 'G' || ch_Ar == 'H'|| ch_Ar== 'I')

return 4;

else if(ch_Ar== 'J' || ch_Ar == 'K'|| ch_Ar == 'L')

return 5;

else if(ch_Ar== 'M' || ch_Ar == 'N'|| ch_Ar == 'O')

return 6;

else if(ch_Ar == 'P' || ch_Ar == 'Q'|| ch_Ar == 'R' || ch_Ar == 'S')

return 7;

else if(ch_Ar == 'T' || ch_Ar == 'U'|| ch_Ar == 'V')

return 8;

else if(ch_Ar == 'W' || ch_Ar == 'X'|| ch_Ar == 'Y' || ch_Ar == 'Z')

return 9;

else

return 0;

}

public static void main(String[] ar) //define main method

{

String Phone_Number,output = "";    //define variable

char ch;

int digit;

Scanner ob = new Scanner(System.in);   //create Scanner class object for user input.

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

Phone_Number=ob.next(); //input from user

for(int i = 0 ; i <Phone_Number.length() ; i++)

{

ch = Character.toUpperCase(Phone_Number.charAt(i));  //input change into UpperCase

if(Character.isLetter(ch))  //conditional statement.

{

digit = convert_Number(ch);  //calling function and hold value..

output = output + digit;

System.out.print("The corresponding number is: "+output); //print value.

}

else

{

output = output + ch;

System.out.print(output+" is an invalid input"); //message

}

}

}

}

Output:

Enter a letter : a

The corresponding number is: 2

Enter a letter : A

The corresponding number is: 2

Enter a letter : ++

+ is an invalid input

Explanation:

In the above java program firstly we import the package for user input. Then we declare class i.e Main.In this class, we declare a function that is convert_Number. This function uses the if-else statement. In the if statement we use the OR (||)operator that is used to check multiple values in that operator if any of the conditions is true it returns a value. else return 0; Then we declare the main method in this method we declare the variable that is Phone_Number, output, ch_Ar, and digit. In that first two variables are string type and one is char and integer type. Then we create a scanner class object for user input and hold the value in the Phone_number variable. Then we declare loop and change the user input into the uppercase and hold the value into the ch_Ar variable and use the if-else statement. In if statement if the value matches then the digit variable the value of called function and it prints the value else condition not match then it will print its corresponding number that is invalid input.

You might be interested in
Laura is the first person in her SDLC team to detect and predict security vulnerabilities in the software. In which phase is Lau
Eddi Din [679]

Answer:

answer is c

if my answer is wrong than sorry

7 0
3 years ago
Flowchart in programming
ArbitrLikvidat [17]

Answer:

?

Explanation:

7 0
3 years ago
30 POINTS FOR THE CORRECT ANSWER
Nonamiya [84]

In the case above, Ruben  should consider the printing option below:

  • Offset litho printing.
  • Digital Printing.
  • Screen printing.

<h3>What is the best printing type for books?</h3>

The use of digital printing is known to be the best in the case with Ruben. It is said to be much more economical in terms of shorter print runs.

Note that Digital printing do have fast turnaround time and as such it is better for books.

Therefore, In the case above, Ruben  should consider the printing option below:

  • Offset litho printing.
  • Digital Printing.
  • Screen printing.

Learn more about printing from

brainly.com/question/145385

#SPJ1

5 0
2 years ago
How can I create an app ? What should I download from the App Store ? How can I put my app in the App Store ? PLEASE GIVE ME THE
crimeas [40]
It's not easy to create an app for cellphones it is harder than to create those for computers. You would need to learn swift coding language to create an application. 
6 0
3 years ago
Read 2 more answers
How to find radius of the base examples ​
Mademuasel [1]

Answer:radius is half the diameter

Explanation:

3 0
3 years ago
Other questions:
  • What are words with the root gest?
    15·1 answer
  • A centralized structure does not provide information from local stores that would be useful in changing its technology quickly.
    15·1 answer
  • What is the value of length after the code that follows is executed?int[][] nums = { new int [] {1, 2, 3},new int [] {3, 4, 5, 6
    8·1 answer
  • In Python please:
    12·1 answer
  • What do u say to your bf if he says sayy lesssss
    14·2 answers
  • Write a program that receives an character and displays its Unicode. Here is a sample run: Enter an character: E The Unicode for
    8·1 answer
  • Intranets:
    8·1 answer
  • Q1) write a brief note on desktop computer.
    13·1 answer
  • It is manadatory to include a banner marking at the top of the page to alert the user that cui is present.
    9·2 answers
  • When would it be appropriate to run MS Office or Adobe on the Windows OS server ?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!