We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I solved this problem using Java's BigInteger DataType which is ment to handle very large inputs. I believe using BigInteger is appropriate for this problem as this problem is about Java Data Types.
importjava.io.*;importjava.util.*;importjava.math.BigInteger;publicclassSolution{staticBigIntegerbn=BigInteger.valueOf(Byte.MIN_VALUE);staticBigIntegerbp=BigInteger.valueOf(Byte.MAX_VALUE);staticBigIntegersn=BigInteger.valueOf(Short.MIN_VALUE);staticBigIntegersp=BigInteger.valueOf(Short.MAX_VALUE);staticBigIntegerin=BigInteger.valueOf(Integer.MIN_VALUE);staticBigIntegerip=BigInteger.valueOf(Integer.MAX_VALUE);staticBigIntegerln=BigInteger.valueOf(Long.MIN_VALUE);staticBigIntegerlp=BigInteger.valueOf(Long.MAX_VALUE);publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);intloopcount=sc.nextInt();for(inti=1;i<=loopcount;i++){BigIntegern=sc.nextBigInteger();if(n.compareTo(bn)>=0&&n.compareTo(bp)<=0){System.out.println(n+" can be fitted in:\n* byte\n* short\n* int\n* long");}elseif(n.compareTo(sn)>=0&&n.compareTo(sp)<=0){System.out.println(n+" can be fitted in:\n* short\n* int\n* long");}elseif(n.compareTo(in)>=0&&n.compareTo(ip)<=0){System.out.println(n+" can be fitted in:\n* int\n* long");}elseif(n.compareTo(ln)>=0&&n.compareTo(lp)<=0){System.out.println(n+" can be fitted in:\n* long");}else{System.out.println(n+" can't be fitted anywhere.");}}}}
Cookie support is required to access HackerRank
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 →
I solved this problem using Java's BigInteger DataType which is ment to handle very large inputs. I believe using BigInteger is appropriate for this problem as this problem is about Java Data Types.