Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1.     public static void multipleChoice() {
  2.        
  3.         Scanner sc = new Scanner(System.in);
  4.         String question = "What is the correct way to declare a variable to store an integer value in Java?";
  5.         System.out.println(question);
  6.         System.out.println("a. int 1x=10");
  7.         System.out.println("b. int x=10");
  8.         System.out.println("c. float x=10.0f");
  9.         System.out.println("d. string x=\"10\"");
  10.         char correct_choice = 'b';
  11.         char user_choice;
  12.         do {
  13.             System.out.println("Enter your choice:");
  14.             user_choice = sc.nextLine().charAt(0);
  15.  
  16.             if (correct_choice == user_choice) {
  17.                 System.out.println("You are right");
  18.  
  19.             } else {
  20.                 System.out.println("You are wrong");
  21.                 // System.out.println("Correct choice is:" + correct_choice);
  22.             }
  23.         } while (correct_choice != user_choice);
  24.         sc.close();
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement