Math Tutor

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Java

Write a program that generates a math problem and solves it. It should generate two numbers and apply one operation between them. These problems should be generated using the java.util.Random class and its nextInt method.

Input

The first line will contain an integer representing the seed to be passed to the Random class. The seed is guaranteed to fit within a 64 bit integer.
The next line contains one of +, -, * or / representing the operation the generated question should have.

Output

Generate two values, a and b that are between 0 (inclusive) and 100 (exclusive).
Then, output a, followed by the operation, then b, followed by an equals sign, then the answer.
For division, the answer should be truncated to a whole number. Do not output any spaces.

Sample Input

8464689454601595904
+

Sample Output

69+41=110

Explanation for Sample

When the seed 8464689454601595904 is used to generate two numbers between 0 and 100, the Random class generates the numbers 69 and 41. Using the addition operation, the sum of these numbers is 110.

Hint for Java Solution

To get the operator as input, you will need to get it as a String. I suggest then converting it and storing it as a char so that you can compare it easily using the == operator which only works with primitive data types.

For example:

// get a String and from that get the character at position 0 (first character)
char operator = input.next().charAt(0);

Comments

There are no comments at the moment.