Consider you are asked to decode a secret message. The coded message is in numbe
ID: 3750642 • Letter: C
Question
Consider you are asked to decode a secret message. The coded message is in numbers and each number stands for a specific letter. You discover enough of the secret code to decode the current message. So far, you know: • 1 represents “D” • 2 represents “W” • 3 represents “E” • 4 represents “L” • 5 represents “H” • 6 represents “O” • 7 represents “R” Write a program in java that prompts the user for 10 numbers, one at a time, and prints out the decoded message. If the user enters a number that is not one of those already deciphered, prompt him/her for a new number. Test your code with the following input: 5 3 4 4 6 2 6 7 4 1
Explanation / Answer
import java.util.*;
class Decipher{
public static void main(String args[])
{
int n;
Scanner sc=new Scanner(System.in);
for(int i=0;i<10;i++)
{
System.out.println("Enter a number :");
n=sc.nextInt();
if(n>7||n<1)
{
System.out.println("This number is not decoded, enter new number!");
i--;
}
switch(n)
{
case 1:
System.out.println("D");
break;
case 2:
System.out.println("W");
break;
case 3:
System.out.println("E");
break;
case 4:
System.out.println("L");
break;
case 5:
System.out.println("H");
break;
case 6:
System.out.println("O");
break;
case 7:
System.out.println("R");
break;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.