import java.util.*; public class SimpleMathGame2 { public static void main(String[] args) { Scanner in=new Scanner(System.in); Random g=new Random(); System.out.println("Hi, I'm going to ask you four simple math questions. Let's see how many you can get right!"); int v1, v2, v3, op, answer, count=0; v1=g.nextInt(10)+1; v2=g.nextInt(20)-10; op=g.nextInt(2); if(op==0) { v3=v1+v2; System.out.print("The problem is: " + v1 + " + " + v2 + " = ? "); } else { v3=v1-v2; System.out.print("The problem is: " + v1 + " - " + v2 + " = ? "); } answer=in.nextInt(); if(answer==v3) { System.out.println("Congratulations, you got it right!"); count++; } else System.out.println("Sorry, the answer is " + v3); v1=g.nextInt(20)+1; v2=g.nextInt(40)-20; op=g.nextInt(2); if(op==0) { v3=v1+v2; System.out.print("The problem is: " + v1 + " + " + v2 + " = ? "); } else { v3=v1-v2; System.out.print("The problem is: " + v1 + " - " + v2 + " = ? "); } answer=in.nextInt(); if(answer==v3) { System.out.println("Congratulations, you got it right!"); count++; } else System.out.println("Sorry, the answer is " + v3); v1=g.nextInt(10)+1; v2=g.nextInt(20)-10; op=g.nextInt(2); if(op==0) { v3=v1*v2; System.out.print("The problem is: " + v1 + " * " + v2 + " = ? "); } else { v3=v1/v2; System.out.print("The problem is: " + v1 + " / " + v2 + " = ? "); } answer=in.nextInt(); if(answer==v3) { System.out.println("Congratulations, you got it right!"); count++; } else System.out.println("Sorry, the answer is " + v3); v1=g.nextInt(20)+1; v2=g.nextInt(40)-20; op=g.nextInt(2); if(op==0) { v3=v1*v2; System.out.print("The problem is: " + v1 + " * " + v2 + " = ? "); } else { v3=v1/v2; System.out.print("The problem is: " + v1 + " / " + v2 + " = ? "); } answer=in.nextInt(); if(answer==v3) { System.out.println("Congratulations, you got it right!"); count++; } else System.out.println("Sorry, the answer is " + v3); System.out.println("\n\nYou got " + count + " correct."); } }