-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch_case6.java
30 lines (28 loc) · 927 Bytes
/
switch_case6.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
import java.util.Scanner;
//7. Write a Java program to create Simple Calculator using switch case.
public class switch_case6 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter first number");
int a=sc.nextInt();
System.out.println("enter the second number");
int b=sc.nextInt();
char n=sc.next().charAt(0);
switch (n){
case '+':
System.out.println(a+b);
break;
case '*':
System.out.println(a*b);
break;
case '/':
System.out.println(a/b);
break;
case '-':
System.out.println(a-b);
break;
default:
System.out.println("enter a valid character and try again!!");
}
}
}