Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void multipleChoice() {
- Scanner sc = new Scanner(System.in);
- String question = "What is the correct way to declare a variable to store an integer value in Java?";
- System.out.println(question);
- System.out.println("a. int 1x=10");
- System.out.println("b. int x=10");
- System.out.println("c. float x=10.0f");
- System.out.println("d. string x=\"10\"");
- char correct_choice = 'b';
- char user_choice;
- do {
- System.out.println("Enter your choice:");
- user_choice = sc.nextLine().charAt(0);
- if (correct_choice == user_choice) {
- System.out.println("You are right");
- } else {
- System.out.println("You are wrong");
- // System.out.println("Correct choice is:" + correct_choice);
- }
- } while (correct_choice != user_choice);
- sc.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement