-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerRange2.java
More file actions
34 lines (27 loc) · 1.58 KB
/
Copy pathIntegerRange2.java
File metadata and controls
34 lines (27 loc) · 1.58 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
import java.text.DecimalFormat;
import java.util.Scanner;
public class IntegerRange2 {
public static void main(String[] args) {
//variable
Scanner range = new Scanner(System.in);
DecimalFormat decFormat = new DecimalFormat("0.#");
byte byteMin = (byte) (-1 * Math.pow(2, 7)), byteMax = (byte) (Math.pow(2, 7) - 1);
short shortMin = (short) (-1 * Math.pow(2, 15)), shortMax = (short) (Math.pow(2, 15) - 1);
int intMin = (int) (-1 * Math.pow(2, 31)), intMax = (int) (Math.pow(2, 31) - 1);
long longMin = (long) (-1 * Math.pow(2, 63)), longMax = (long) (Math.pow(2, 63) - 1);
int Times = range.nextInt();
for(int i = 0; i < Times; i++){
var theNumber = range.nextDouble();
if (theNumber < longMin || theNumber > longMax)
System.out.println(decFormat.format(theNumber) + " can't be fitted anywhere.");
else if (theNumber >= byteMin && theNumber <= byteMax)
System.out.println(decFormat.format(theNumber) + " can be fitted in:\n* byte\n* short\n* int\n* long");
else if(theNumber >= shortMin && theNumber <= shortMax)
System.out.println(decFormat.format(theNumber) + " can be fitted in:\n* short\n* int\n* long");
else if(theNumber >= intMin && theNumber <= intMax)
System.out.println(decFormat.format(theNumber) + " can be fitted in:\n* int\n* long");
else
System.out.println(decFormat.format(theNumber) + " can be fitted in:\n* long");
}
}
}