Question & Answer: Write a program that prompts the user to enter a 10 alphabets (A-Z) and converts it to numbers u…..

1) Please write this program in Java

Write a program that prompts the user to enter a 10 alphabets (A-Z) and converts it to numbers using the following mapping:

A, B, C = 8

D, E, F = 6

G, H, I = 4

J, K, L = 5

M, N, 0 = 7

P, Q, R, S = 2

T, U, V, W = 3

X, Y, Z = 1

Expert Answer

 

//Alphabets.java
import java.util.Scanner;
public class Alphabets {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
int number = 8;
System.out.print(“Enter alphabet: “);
String alphabet = input.nextLine();

if(alphabet.equals(“D”) || alphabet.equals(“E”) || alphabet.equals(“F”))
number = 6;
else if(alphabet.equals(“G”) || alphabet.equals(“H”) || alphabet.equals(“I”))
number = 4;
else if(alphabet.equals(“J”) || alphabet.equals(“K”) || alphabet.equals(“L”))
number = 5;
else if(alphabet.equals(“M”) || alphabet.equals(“N”) || alphabet.equals(“O”))
number = 7;
else if(alphabet.equals(“P”) || alphabet.equals(“Q”) || alphabet.equals(“R”) || alphabet.equals(“S”))
number = 2;
else if(alphabet.equals(“T”) || alphabet.equals(“U”) || alphabet.equals(“V”) || alphabet.equals(“W”))
number = 3;
else if(alphabet.equals(“X”) || alphabet.equals(“Y”) || alphabet.equals(“Z”))
number = 1;

System.out.println(“Number corresponding to alphabet ” + alphabet + ” is ” + number);

}
}

Question & Answer: Write a program that prompts the user to enter a 10 alphabets (A-Z) and converts it to numbers u..... 1

Still stressed from student homework?
Get quality assistance from academic writers!