public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
BigInteger number = new BigInteger(input.nextLine());
int bitLength = number.bitlength();
if (bitLength <= Bytes.SIZE)
System.out.println("\u8211 byte");
if (bitLength <= Short.SIZE)
System.out.println("\u8211 short");
if (bitLength <= Int.SIZE)
System.out.println("\u8211 int");
if (bitLength <= Long.SIZE)
System.out.println("\u8211 long");
if (bitLength > Long.SIZE)
System.out.println(number + " can't be fitted anywhere.");
}
}
Task : to find a suitable data type Sample Input :5
-150
150000
1500000000
213333333333333333333333333333333333
-100000000000000
Sample Output :
-150 can be fitted in:
short
int
long
150000 can be fitted in:
int
long
1500000000 can be fitted in:
int
long
213333333333333333333333333333333333 can't be fitted anywhere.
-100000000000000 can be fitted in:
long
Error 1:
error: cannot find symbol
int bitLength = number.bitlength();
^
Error 2:
symbol: method bitlength()
location: variable number of type BigInteger
Error 3:
error: cannot find symbol
if (bitLength <= Int.SIZE)
^
symbol: variable Int
location: class Solution
int number = input.nextInt();
can't return something bigger than int – VacationbitLength
notbitlength
, I have fixed this in my answer. – Crowdjava.lang.Integer
, notInt
. – Culinarian