-
Notifications
You must be signed in to change notification settings - Fork 2
/
CalculatorAllOperations.java
69 lines (57 loc) · 1.5 KB
/
CalculatorAllOperations.java
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
import java.util.Scanner;
public class CalculatorAllOperations {
public static void main(String[] args) {
int num1;
int num2;
int answer;
String operation;
Scanner input = new Scanner(System.in);
System.out.println("Please Enter The First Number");
num1 = input.nextInt();
System.out.println("Please Enter The Second Number");
num2 = input.nextInt();
Scanner op = new Scanner (System.in);
System.out.println("Please Enter The Operation");
operation = op.next();
if (operation.equals("+"))
{
answer = add(num1, num2);
System.out.println("Your Answer is "+ answer);
}
else if (operation.equals("-"))
{
answer = subtract(num1, num2);
System.out.println("Your Answer is "+ answer);
}
else if (operation.equals("*"))
{
answer = multiply(num1, num2);
System.out.println("Your Answer is "+ answer);
}
else if (operation.equals("/"))
{
answer = divide(num1, num2);
System.out.println("Your Answer is "+ answer);
}
}
public static int add(int x, int y)
{
int result = x + y;
return result;
}
public static int subtract(int x, int y)
{
int result = x - y;
return result;
}
public static int multiply(int x, int y)
{
int result = x * y;
return result;
}
public static int divide(int x, int y)
{
int result = x / y;
return result;
}
}