Created
May 30, 2018 08:13
-
-
Save cxubrix/e7762a3168fb25c7c0b8b7f883a9f67a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class GameWithTimer { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
Random rand = new Random(); | |
int c = 10; | |
for (int i = 0; i < 10; i++) { | |
int a = rand.nextInt(c); | |
// System.out.print(a); | |
int b = rand.nextInt(c); | |
// System.out.println(b); | |
int operator = rand.nextInt(4); | |
// System.out.println(b); | |
int result1 = -1; | |
int result = -1; | |
switch (operator) { | |
case 1: | |
result = a + b; | |
System.out.println(a + "+" + b + "= "); | |
result1 = input.nextInt(); | |
break; | |
case 2: | |
result = a - b; | |
System.out.println(a + "-" + b + "= "); | |
result1 = input.nextInt(); | |
break; | |
case 3: | |
result = a * b; | |
System.out.println(a + "*" + b + "= "); | |
result1 = input.nextInt(); | |
break; | |
case 4: | |
result = a / b; | |
System.out.println(a + "/" + b + "= "); | |
result1 = input.nextInt(); | |
break; | |
default: | |
break; | |
} | |
if (result == result1) { | |
System.out.println("correct"); | |
} else { | |
System.out.println("wrong"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment