Advertisement
damoncard

Plus Quizes

Oct 9th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Random; // import Random tool
  2. import java.util.Scanner; // import Scanner tool
  3. public class Test {
  4.   public static void main (String [] args) {
  5.     int z;
  6.     int count = 0;
  7.     Random ran = new Random();
  8.     Scanner sc = new Scanner (System.in);
  9.     int a = ran.nextInt(100)+1;
  10.     int b = ran.nextInt(100)+1;
  11.     System.out.print("Are you ready? Y/N");
  12.     String q = sc.nextLine();
  13.     if (q.equalsIgnoreCase("Y"))
  14.     {
  15.       do {
  16.         a = ran.nextInt(100)+1; // random number 1
  17.         b = ran.nextInt(100)+1; // random number 2
  18.         System.out.print("What is "+a+ " + "+b);
  19.         z = sc.nextInt();
  20.         if (z == a+b)
  21.         {
  22.           count++;
  23.           continue; // skip one loop (this time)
  24.         }
  25.         break; // break the loop
  26.       } while(z == a+b);
  27.       System.out.print("You correct "+count+" questions");
  28.     } else {
  29.       System.out.print("See you next time");
  30.     }
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement