forked from CS816SPE/git-java-branches-Abhay2608
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.java
More file actions
40 lines (35 loc) · 1011 Bytes
/
calc.java
File metadata and controls
40 lines (35 loc) · 1011 Bytes
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
import java.util.*;
public class calc{
public static void main(String[] args){
float a,b,res;
char choice,ch;
Scanner scan = new Scanner(System.in);
do{
System.out.print("1. ADD TWO Numbers\n");
System.out.print("2. Exit\n\n");
System.out.print("3. SUBTRACT\n");
System.out.print("4. multiply TWO Numbers\n");
System.out.print("Enter choice: ");
choice = scan.next().charAt(0);
switch(choice){
case '1':System.out.print("Enter two numbers");
a = scan.nextFloat();
b = scan.nextFloat();
res = a + b;
System.out.print("Result = " + res);
break;
case '3':System.out.print("Enter two numbers");
a = scan.nextFloat();
b = scan.nextFloat();
res = a - b;
System.out.print("Result = " + res);
break;
case '2' :System.exit(0);
break;
default: System.out.print("Invalid choice");
break;
}
System.out.print("\n-------------------------\n");
}while(choice !=2);
}
}