Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random; // import Random tool
- import java.util.Scanner; // import Scanner tool
- public class Test {
- public static void main (String [] args) {
- int z;
- int count = 0;
- Random ran = new Random();
- Scanner sc = new Scanner (System.in);
- int a = ran.nextInt(100)+1;
- int b = ran.nextInt(100)+1;
- System.out.print("Are you ready? Y/N");
- String q = sc.nextLine();
- if (q.equalsIgnoreCase("Y"))
- {
- do {
- a = ran.nextInt(100)+1; // random number 1
- b = ran.nextInt(100)+1; // random number 2
- System.out.print("What is "+a+ " + "+b);
- z = sc.nextInt();
- if (z == a+b)
- {
- count++;
- continue; // skip one loop (this time)
- }
- break; // break the loop
- } while(z == a+b);
- System.out.print("You correct "+count+" questions");
- } else {
- System.out.print("See you next time");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement