-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
48 lines (41 loc) · 1.14 KB
/
Calculator.java
File metadata and controls
48 lines (41 loc) · 1.14 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
import java.util.Scanner;
public class Calculator {
public static int Multiply(int x, int y){
int product = x * y;
return product;
}
public static int Divide(int x, int y){
int quotient = x / y;
return quotient;
}
public static int Add(int x, int y){
int sum = x + y;
return sum;
}
public static int Subtract(int x, int y){
int difference = x - y;
return difference;
}
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the first number");
int x = scan.nextInt();
System.out.println("Enter the second number");
int y = scan.nextInt();
System.out.println("Which operation would you like to do? (x*y x/y x+y x-y)");
System.out.println("1: Multiplication, 2: Division, 3: Addition, 4: Subtraction (type 1 2 3 or 4");
int input = scan.nextInt().trim();
if(int input==1){
System.out.println(x + " * " + y + "=" + Multiply(x,y));
}
else if (int input==2) {
System.out.println((x + " / " + y + "=" + Divide(x,y));
}
else if (int input==3) {
System.out.println((x + " + " + y + "=" + Add(x,y));
}
else if (int input==4) {
System.out.println((x + " - " + y + "=" + Subtract(x,y));
}
}
}