-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSolution.java
More file actions
40 lines (35 loc) · 1.01 KB
/
Solution.java
File metadata and controls
40 lines (35 loc) · 1.01 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
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
try {
long num = in.nextLong();
System.out.println(num + " can be fitted in:");
printValidDatatypes(num);
} catch (Exception e) {
String invalid = in.next();
System.out.println(invalid + " can't be fitted anywhere.");
}
}
}
public static void printValidDatatypes(long num) {
if (num >= -Math.pow(2, 7) && num < Math.pow(2, 7)) {
System.out.println("* byte");
}
if (num >= -Math.pow(2, 15) && num < Math.pow(2, 15)) {
System.out.println("* short");
}
if (num >= -Math.pow(2, 31) && num < Math.pow(2, 31)) {
System.out.println("* int");
}
if (num >= -Math.pow(2, 63) && num < Math.pow(2, 63)) {
System.out.println("* long");
}
}
}