# I made a simple calculation problem game in Java

Suddenly, I remembered a game called DS training for adults who train their brains. Training on how to quickly solve the addition recorded in the game I wanted to play, so I wrote the program myself. Below is the code.

#### `Main.java`

``````
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Random;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
int count = 0;
long start = 0;
long stop = 0;
long timeresult = 0;
Scanner sc = new Scanner(System.in);
System.out.println("I will give you a calculation problem.");
System.out.println("You will be asked 10 questions.");
String anykey = sc.nextLine();
System.out.println("------------------------------");

for(int i = 0; i < 10; i++) {
start = System.nanoTime();
Random rnd = new Random();
int figure1 = rnd.nextInt(30) + 1;
int figure2 = rnd.nextInt(30) + 1;
int result = figure1 + figure2;
System.out.println(figure1 + " + " + figure2 + " = ?");
int a = sc.nextInt();
if(result == a) {
count++;
} else {
}
}
stop = System.nanoTime();
System.out.println("------------------------------");
timeresult = stop - start;
double timesecond = timeresult / 100000000.0;
BigDecimal bdt = new BigDecimal(String.valueOf(timesecond));
BigDecimal bdt1 = bdt.setScale(2, RoundingMode.HALF_UP);
System.out.println("The number of correct answers is" + count + "It was a question.");
System.out.println("The time it took to solve" + bdt1 + "It was seconds.");
}
}
``````

In this game, 10 questions are added in a row, and the player solves them. When the game is over, the number of correct answers and the clearing time will be displayed. I found out by actually playing it, but if you try to solve it quickly I make a calculation error. Also, in the DS brain training, I wrote the answer with a touch pen, but here is Because it is input with the keyboard, it is necessary to get used to inputting numbers quickly and continuously thought. It's a very simple game, but it's a lot of fun.

# What i learned

I learned about the existence of a method called nanoTime. I feel that it is very versatile, and at the same time, it is suitable for programs of various genres. I thought it could be used.

# If you want to add more

In the DS brain training, evaluations such as "walking class" and "Shinkansen class" are given depending on the training results. I remember it well. Even in this program, even if there is such an expression as a comprehensive evaluation of the number of correct answers and clearing time I thought it was interesting.