0
How do I add a While, For, or do loop to make the code continue until the user enters a sentinel value or keyword?
2 Antworten
0
import java.util.Scanner;
public class RPSTester {
public static void main(String[] args) {
String winner = "";
Scanner obj1 = new Scanner (System.in);
System.out.println("Enter Rock, Paper or Scissors: ");
String userChoice = obj1.nextLine();
if (userChoice.equalsIgnoreCase("Rock") || userChoice.equalsIgnoreCase("Paper") || userChoice.equalsIgnoreCase("Scissors"))
{
winner += userChoice;
System.out.println(winner);
}
else
System.out.println("Please enter a valid value");
}
}
Your above code atleast works now.
0
Thanks