-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerRange.java
More file actions
27 lines (24 loc) · 1.34 KB
/
Copy pathIntegerRange.java
File metadata and controls
27 lines (24 loc) · 1.34 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
import java.util.Scanner;
public class IntegerRange {
public static void main(String[] args) {
//variable
Scanner range = new Scanner(System.in);
double theNumber;
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);
System.out.print("Give me the number!\n$ ");
theNumber = range.nextDouble();
if (theNumber < longMin || theNumber > longMax)
System.out.println(theNumber + " can't be fitted anywhere.");
else if (theNumber >= byteMin && theNumber <= byteMax)
System.out.println(theNumber + " can be fitted in:\n* byte\n* short\n* int\n* long");
else if(theNumber >= shortMin && theNumber <= shortMax)
System.out.println(theNumber + " can be fitted in:\n* short\n* int\n* long");
else if(theNumber >= intMin && theNumber <= intMax)
System.out.println(theNumber + " can be fitted in:\n* int\n* long");
else
System.out.println(theNumber + " can be fitted in:\n* long");
}
}