You are viewing a single comment's thread. Return to all comments →
It's not the best example for a solution, I'm just posting my solution:
import java.io.; import java.math.BigInteger; import java.util.;
public class DatatypeFitter {
public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int q = Integer.parseInt(bufferedReader.readLine().trim()); for (int i = 0; i < q; i++) { String strNum = bufferedReader.readLine().trim(); BigInteger numBigDecimal = new BigInteger(strNum); int isBiggerThanLong = numBigDecimal.compareTo(BigInteger.valueOf(Long.MAX_VALUE)); int isSmallerThanLong = numBigDecimal.compareTo(BigInteger.valueOf(Long.MIN_VALUE)); if (isBiggerThanLong > 0 || isSmallerThanLong < 0) { System.out.println(strNum + " can't be fitted anywhere."); } else { System.out.println(strNum + " can be fitted in:"); long num = numBigDecimal.longValue(); if (num >= Byte.MIN_VALUE && num <= Byte.MAX_VALUE) { System.out.println("* byte"); } if (num >= Short.MIN_VALUE && num <= Short.MAX_VALUE) { System.out.println("* short"); } if (num >= Integer.MIN_VALUE && num <= Integer.MAX_VALUE) { System.out.println("* int"); } System.out.println("* long"); } } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Datatypes
You are viewing a single comment's thread. Return to all comments →
It's not the best example for a solution, I'm just posting my solution:
import java.io.; import java.math.BigInteger; import java.util.;
public class DatatypeFitter {
}