-
Notifications
You must be signed in to change notification settings - Fork 0
/
Datatypes.java
36 lines (34 loc) · 1.25 KB
/
Datatypes.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
33
34
35
36
import java.util.*;
import java.lang.*;
import java.io.*;
public class Datatypes {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int loop = sc.nextInt();
for(int i = 0; i < loop; i++) {
try {
long num = sc.nextLong();
System.out.printf("%d can be fitted in:%n", num);
if (num >= -Math.pow(2, 7) && num <= (Math.pow(2, 7) - 1 )) {
System.out.println("* byte");
}
if (num >= -Math.pow(2, 15) && num <= (Math.pow(2, 15) - 1 )) {
System.out.println("* short");
}
if (num >= -Math.pow(2, 31) && num <= (Math.pow(2, 31) - 1 )) {
System.out.println("* int");
}
if (num >= -Math.pow(2, 63) && num <= (Math.pow(2, 63) - 1 )) {
System.out.println("* long");
}
}
catch(InputMismatchException e) {
String str = sc.next();
System.out.printf("%s can't be fitted anywhere.%n", str);
}
catch(NoSuchElementException e) {
System.out.println("No element present");
}
}
}
}