-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch.java
42 lines (42 loc) · 1.08 KB
/
switch.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
//Write a program in java to make simple calculator using switch
import java.util.Scanner;
class calculator
{
public static void main(String [] args)
{
Scanner s=new Scanner(System.in);
double n1,n2,res;
int ch;
System.out.println("Enter First No n1=");
n1=s.nextDouble();
System.out.println("Enter Second No n2=");
n2=s.nextDouble();
System.out.println("Enter 1 for addition=");
System.out.println("Enter 2 for substraction=");
System.out.println("Enter 3 for multipication=");
System.out.println("Enter 4 for Divison=");
ch=s.nextInt();
switch(ch)
{
case 1:
res=n1+n2;
System.out.println("Addition is="+res);
break;
case 2:
res=n1-n2;
System.out.println("Substraction is="+res);
break;
case 3:
res=n1*n2;
System.out.println("Substraction is="+res);
break;
case 4:
res=n1/n2;
System.out.println("Division is="+res);
break;
default:
System.out.println("Enter Wrong Choice");
break;
}
}
}