Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote