-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
41 lines (35 loc) · 1.07 KB
/
Copy pathCalculator.java
File metadata and controls
41 lines (35 loc) · 1.07 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
package springlab.SpringLabs;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Type the operation");
String op = input.nextLine();
System.out.println("Type first integer");
Double a = (double) input.nextInt();
System.out.println("Type second integer");
double b = input.nextDouble();
input.close();
System.out.println("Here's your result");
if (op.equals("addition")){
System.out.println(addition(a, b));
}else if(op.equalsIgnoreCase("subtraction")) {
System.out.println(sub(a, b));
}else if(op.equalsIgnoreCase("multiplication")) {
System.out.println(multi(a, b));
}else if (op.equalsIgnoreCase("division")) {
System.out.println(div(a, b));
}
}
public static double addition(double one,double two) {
return one + two;
}
public static double sub(double one,double two) {
return one-two;
}
public static double div(double one,double two) {
return one/two;
}public static double multi(double a,double two) {
return a*two;
}
}