Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- System.out.println("start math test ? y/n");
- String c = s.next();
- if(c == "n") return;
- else StartMath();
- }
- private static void StartMath() {
- Random r = new Random();
- Scanner s = new Scanner(System.in);
- System.out.println("choose a level 1-3");
- int level = s.nextInt();
- if(level < 1 || level > 3) return;
- System.out.println("I will ask you 20 question and you need to answer the most fast as you can - and right!");
- Date date = new Date();
- long d = date.getTime();
- int num1=0,num2=0;
- int correct=0;
- for(int i = 1;i <= 20;i++) {
- if(level == 1) {
- num1 = r.nextInt(10);
- num2 = r.nextInt(10);
- }
- else if(level == 2) {
- num1 = r.nextInt(100);
- num2 = r.nextInt(100);
- }
- else {
- num1 = r.nextInt(1000);
- num2 = r.nextInt(1000);
- }
- System.out.println("Question " + i);
- System.out.println(num1 + "-" + num2 + "=?");
- int answer = s.nextInt();
- if(answer == num1-num2) {
- correct++;
- System.out.println("You answer right! good job!");
- }
- else System.out.println("Your answer was wrong!");
- }
- System.out.println("You answer " + correct + " correct and " + (20-correct) + " wrong!");
- Date date2 = new Date();
- long d2 = date2.getTime();
- System.out.println("it take you " + (d-d2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement