-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaDataTypes.java
More file actions
35 lines (30 loc) · 904 Bytes
/
Copy pathJavaDataTypes.java
File metadata and controls
35 lines (30 loc) · 904 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
33
34
35
package HackerRankSolution;
import java.util.Scanner;
public class JavaDataTypes {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for (int i = 0; i < t; i++) {
try {
long n = scan.nextLong();
System.out.println(n+" can be fitted in:");
if (n >= Byte.MIN_VALUE && n <= Byte.MAX_VALUE) {
System.out.println("* byte");
}
if (n >= Short.MIN_VALUE && n <= Short.MAX_VALUE) {
System.out.println("* short");
}
if (n >= Integer.MIN_VALUE && n <= Integer.MAX_VALUE) {
System.out.println("* int");
}
if (n >= Long.MIN_VALUE && n <= Long.MAX_VALUE) {
System.out.println("* long");
}
} catch (Exception e) {
System.out.println(scan.next()+" can't be fitted anywhere.");
}
}
scan.close();
}
}