forked from klmntv27/ulearn-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.1.java
More file actions
32 lines (31 loc) · 726 Bytes
/
2.1.java
File metadata and controls
32 lines (31 loc) · 726 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
public static float calculate(int a, int b, String operation) {
switch (operation) {
case "+":
return a + b;
case "-":
return a - b;
case "*":
return a * b;
case "/":
if (b != 0)
return (float) a / (float) b;
else return 0;
case "%":
if (b != 0)
return a % b;
else return 0;
default:
return 0;
}
}
public static String getMinimalType(String input) {
long num = Long.parseLong(input);
if (num <= Byte.MAX_VALUE && num >= Byte.MIN_VALUE)
return ("Byte");
else if (num <= Short.MAX_VALUE && num >= Short.MIN_VALUE)
return ("Short");
else if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE)
return ("Int");
else
return ("Long");
}