-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath Methods.txt
More file actions
85 lines (79 loc) · 2.08 KB
/
Math Methods.txt
File metadata and controls
85 lines (79 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.util.Scanner;
import java.util.Random;
public class Main
{
public static void addTwoNumbers()
{
Scanner answer = new Scanner(System.in);
Random rnd = new Random();
int num1 = rnd.nextInt(20) + 1;
int num2 = rnd.nextInt(20) + 1;
int total = num1 + num2;
System.out.print(num1 + " + " + num2 + " =");
int number = answer.nextInt();
if(number != total)
{
System.out.println("Wrong! The correct answer is " + total);
}
else
{
System.out.println("Correct!");
}
}
public static void diffTwoNumbers()
{
Scanner answer = new Scanner(System.in);
Random rnd = new Random();
int num1 = rnd.nextInt(20) + 1;
int num2 = rnd.nextInt(20) + 1;
int total = Math.max(num1,num2) - Math.min(num1,num2);
System.out.print(Math.max(num1,num2) + " - " + Math.min(num1,num2) + " =");
int number = answer.nextInt();
if(number != total)
{
System.out.println("Wrong! The correct answer is " + total);
}
else
{
System.out.println("Correct!");
}
}
public static void prodTwoNumbers()
{
Scanner answer = new Scanner(System.in);
Random rnd = new Random();
int num1 = rnd.nextInt(20) + 1;
int num2 = rnd.nextInt(20) + 1;
int total = num1 * num2;
System.out.print(num1 + " * " + num2 + " =");
int number = answer.nextInt();
if(number != total)
{
System.out.println("Wrong! The correct answer is " + total);
}
else
{
System.out.println("Correct!");
}
}
public static void main (String[] args)
{
Scanner letter = new Scanner(System.in);
System.out.println("What do you want to practice?");
System.out.println("(A)ddition, (S)ubtraction or (M)ultiplication.");
String choice = letter.nextLine();
switch(choice) {
case "M":
prodTwoNumbers();
break;
case "A":
addTwoNumbers();
break;
case "S":
diffTwoNumbers();
break;
default:
System.out.println("Please choose between M, A, or S.");
}
}
}