Sunday, 29 September 2013

Repeating after wrong answer

Repeating after wrong answer

Today I was messing around and I was trying to create a multiple choice
test. I got this far and it works. I was wondering though, how would I
make it repeat the question if the user got the answer wrong? If anyone
could help me out that would be fantastic! Thanks!
import java.util.Scanner;
public class multipleChoiceTest {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
System.out.println("What color is the sky?");
System.out.println("A. Blue");
System.out.println("B. Green");
System.out.println("C. Yellow");
System.out.println("D. Red");
String userChoice = myScanner.nextLine();
if (userChoice.equalsIgnoreCase("a")) {
System.out.println("You're right!");
} else {
System.out.println("You're wrong! Try Again.");
}
}

No comments:

Post a Comment