forked from I-RoshanKumar/Beginner_Hactoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.java
59 lines (48 loc) · 1.21 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
float num1, num2, num3 ;
int choice, n;
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Exit");
do {
//create an object of scanner class
Scanner input = new Scanner(System.in);
System.out.println("Enter first number: ");
num1 = input.nextFloat();
System.out.println("Enter second number: ");
num2 = input.nextFloat();
System.out.println("Enter choice: ");
choice = input.nextInt();
switch(choice) {
case 1:
num3 = num1 + num2;
System.out.println(num3);
break;
case 2:
num3 = num1 - num2;
System.out.println(num3);
break;
case 3:
num3 = num1 * num2;
System.out.println(num3);
break;
case 4:
num3 = num1 / num2;
System.out.println(num3);
break;
case 5:
System.exit(0);
default:
System.out.println("Invalid Choice");
}
System.out.println("Do you want to continue: 1.Yes 2.No");
n = input.nextInt();
}
while(n==1);
System.out.println("ThankYou!!");
}
}