-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.java
45 lines (36 loc) · 1.22 KB
/
calculator.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
package com.company;
import java.util.Scanner;
public class calculator {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n1,n2,select;
double result;
System.out.println("enter first num");
n1=input.nextInt();
System.out.println("enter second num");
n2=input.nextInt();
System.out.println("which type calculation");
System.out.println("For sum enter 1 \t For product enter 2 \t For subtraction enter 3 \t For divide enter 4 \t");
select=input.nextInt();
switch (select){
case 1:
result=n1+n2;
System.out.println("the answer is " + result);
break;
case 2:
result=n1*n2;
System.out.println("the answer is " + result);
break;
case 3:
result=n1-n2;
System.out.println("the answer is " + result);
break;
case 4:
result=(double) n1/n2;
System.out.println("the answer is " + result);
break;
default:
System.out.println("wrong selection");
}
}
}