-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem2.java
32 lines (28 loc) · 1.11 KB
/
problem2.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
31
32
import java.util.Scanner;
public class problem2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt(); // Number of test cases
for (int i = 0; i < t; i++) {
try {
long num = scanner.nextLong(); // Read the input number
// Check if it can fit into different data types
System.out.println(num + " can be fitted in:");
if (num >= Byte.MIN_VALUE && num <= Byte.MAX_VALUE) {
System.out.println("* byte");
}
if (num >= Short.MIN_VALUE && num <= Short.MAX_VALUE) {
System.out.println("* short");
}
if (num >= Integer.MIN_VALUE && num <= Integer.MAX_VALUE) {
System.out.println("* int");
}
System.out.println("* long");
} catch (Exception e) {
System.out.println(scanner.next() + " can't be fitted anywhere.");
}
}
// Close the scanner
scanner.close();
}
}