-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
39 lines (36 loc) · 1.22 KB
/
calculator.java
File metadata and controls
39 lines (36 loc) · 1.22 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
import java.util.*;
public class calculator {
public static void main(String [] argu){
@SuppressWarnings("resource")
Scanner sc = new Scanner (System.in);
System.out.println("( Calculator )");
System.out.print("Enter First Number = ");
int a = sc.nextInt();
System.out.print("Enter Function ( + , - , % , * , / ) = ");
char function = sc.next().charAt(0);
System.out.print("Enter Second Number = ");
int b = sc.nextInt();
System.out.print("Answer = " );
switch(function){
case '+' : System.out.println(a + b);
break;
case '-': System.out.println(a - b);
break;
case '/' : if (b == 0) {
System.out.println("valune can not define");
} else {
System.out.println( a / b);
}
break;
case '%' : if (b == 0) {
System.out.println("valune not define");
} else {
System.out.println(a % b);
}
break;
case '*' : System.out.println( a * b);
break;
default : System.out.println("Undefiend Value");
}
}
}