-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay-03-Java-Q17
More file actions
81 lines (66 loc) · 2.21 KB
/
Copy pathDay-03-Java-Q17
File metadata and controls
81 lines (66 loc) · 2.21 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*Kumar wants to learn how the calculators are working.so he is trying to implements the calculator program.could you please help him to implements the program. - Notes:- Must use the Switch Case.operators - Addition - Subtraction - Multiplication - Division - Modulo
Input Format
First input consists of integer.
Second input consists of integer.
third input consists of character.
Constraints
No Constraints
Output Format
print the calculation Value.
if the symbol is not the arithmetic operator,print the statement is "Invalid Input".
Sample Input 0
3
4
+
Sample Output 0
Addition of two number is 7.0
Sample Input 1
7
3
-
Sample Output 1
Subtraction of two number is 4.0
Sample Input 2
13
2
/
Sample Output 2
Division of two number is 6.5*/
#Answer
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
char operator = sc.next().charAt(0);
double result;
switch(operator) {
case '+':
result = num1 + num2;
System.out.println("Addition of two number is " + result + " ");
break;
case '-':
result = num1 - num2;
System.out.println("Subtraction of two number is " + result + " ");
break;
case '*':
result = num1 * num2;
System.out.println("Multiplication of two number is " + result + " ");
break;
case '/':
result = (double) num1 / num2;
System.out.println("Division of two number is " + result + " ");
break;
case '%':
result = num1 % num2;
System.out.println("Modulo of two number is " + result + " ");
break;
default:
System.out.println("Invalid Input");
}
sc.close();
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
}
}