forked from CS816SPE/Learning_Git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
50 lines (41 loc) · 1.14 KB
/
Calculator.java
File metadata and controls
50 lines (41 loc) · 1.14 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
47
48
49
50
import java.util.Scanner;
public class Calculator
{ public static void main(String args[])
{
float a,b,res;
char choice,ch;
Scanner scan=new Scanner(System.in);
do{ System.out.println("1.Perform Subtraction");
System.out.println("2.Perform Addition");
System.out.println("3.Perform Multiplication");
System.out.println("4.Exit");
System.out.println("Enter your choice: ");
choice=scan.next().charAt(0);
switch(choice)
{ case '1': System.out.println("Enter two numbers: ");
a=scan.nextFloat();
b=scan.nextFloat();
Subtract s =new Subtract(a,b);
s.getRes();
break;
case '2': System.out.println("Enter two numbers: ");
a=scan.nextFloat();
b=scan.nextFloat();
res=a+b;
System.out.println("The result of addition is:" +res);
break;
case '3': System.out.println("Enter two numbers: ");
a=scan.nextFloat();
b=scan.nextFloat();
Multiply m =new Multiply(a,b);
m.getResult();
break;
case '4':System.out.println("Exiting!!!");
System.exit(0);
break;
default:System.out.println("Entered wrong choice!!!");
break;
}
}while(choice!='4');
}
}