asked 29.1k views
1 vote
PLEASE HELP: Write a java code where the user picks a number 1-3 and depending on what number they choose they have to unscramble the word given to them.

If the user is correct display the message. If the user is incorrect display they are wrong. The user only gets one chance.


Example output:


Pick a number 1-3


> 2


Guess the word:

lehlo


> hello


you are correct!

asked
User Saustin
by
8.0k points

1 Answer

4 votes

import java.util.Scanner;

public class JavaApplication37 {

public static void main(String[] args) {

String [] arr = {"lehlo", "ciem", "hrpmsi"};

Scanner scan = new Scanner(System.in);

System.out.println("Pick a number 1-3");

int num = scan.nextInt();

System.out.println("Guess the word:");

System.out.println(arr[num-1]);

String guess = scan.next();

if (num == 1){

if (guess.equals("hello")){

System.out.println("You are correct!");

}

else{

System.out.println("You are incorrect!");

}

}

else if (num == 2){

if (guess.equals("mice")){

System.out.println("You are correct!");

}

else{

System.out.println("You are incorrect!");

}

}

else if (num == 3){

if (guess.equals("shrimp")){

System.out.println("You are correct!");

}

else{

System.out.println("You are incorrect!");

}

}

}

}

I hope this helps!

answered
User Ste
by
8.1k points

No related questions found