- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCalculator.java
More file actions
Latest commit
46 lines (39 loc) · 1.29 KB
/
Copy pathSimpleCalculator.java
File metadata and controls
46 lines (39 loc) · 1.29 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
packagecom.sarvesh.javabasics;
importjava.util.Scanner;
publicclassSimpleCalculator {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
intchoice;
do {
System.out.println("\n 2--- Calculator ---");
System.out.println("1. Addition ");
System.out.println("2. Susbstraction ");
System.out.println("3. Multiplication ");
System.out.println("4. Division ");
System.out.println("5. Exit ");
System.out.println("------------------");
System.out.print("Choice : ");
choice = sc.nextInt();
if (choice >= 1 && choice <= 4) {
System.out.print("Enter 1st Integer : ");
doublenum1 = sc.nextDouble();
System.out.print("Enter 2nd Integer : ");
doublenum2 = sc.nextDouble();
switch(choice) {
case1:
System.out.printf("Addiition of %.2f and %.2f is %.2f.\n", (num1) , (num2) , (num1 + num2 ));
break;
case2:
System.out.printf("Substraction of %.2f with %.2f is %.2f.\n" , (num1) ,(num2) ,(num1-num2));
break;
case3:
System.out.printf("Multiplication of %.2f and %.2f is %.2f.\n" ,(num1) ,(num2) ,(num1*num2));
break;
case4:
System.out.printf("Division of %.2f with %.2f is %.2f.\n",(num1) ,(num2) ,(num1/num2));
}
}
}while (choice!=5);
sc.close();
}
}