-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.java
38 lines (33 loc) · 945 Bytes
/
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
import java.util.Scanner;
public class calculator
{
public static void main(String[] args)
{
float a, b, res;
int choice;
Scanner scan = new Scanner(System.in);
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.print("Enter Your Choice (1-4): ");
choice = scan.nextInt();
if(choice>=1 && choice<=4)
{
System.out.print("\nEnter any Two Number: ");
a = scan.nextFloat();
b = scan.nextFloat();
if(choice==1)
res = a+b;
else if(choice==2)
res = a-b;
else if(choice==3)
res = a*b;
else
res = a/b;
System.out.println("\nResult = " +res);
}
else
System.out.println("\nInvalid Choice!");
}
}