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.
classSolution{publicstaticvoidmain(String[]argh){Scannersc=newScanner(System.in);intt=sc.nextInt();for(inti=0;i<t;i++){try{longx=sc.nextLong();Strings=String.valueOf(x);System.out.println(x+" can be fitted in:");if(checkByte(s)){System.out.println("* byte");}if(checkShort(s)){System.out.println("* short");}if(checkInt(s)){System.out.println("* int");}if(checkLong(s)){System.out.println("* long");}}catch(Exceptione){System.out.println(sc.next()+" can't be fitted anywhere.");}}}privatestaticbooleancheckByte(Stringl){try{byteb=Byte.valueOf(l);returntrue;}catch(Exceptione){returnfalse;}}privatestaticbooleancheckShort(Stringl){try{shorts=Short.valueOf(l);returntrue;}catch(Exceptione){returnfalse;}}privatestaticbooleancheckInt(Stringl){try{inti=Integer.valueOf(l);returntrue;}catch(Exceptione){returnfalse;}}privatestaticbooleancheckLong(Stringl){try{longs=Long.valueOf(l);returntrue;}catch(Exceptione){returnfalse;}}}
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 →
Idk, i dont manage to think as the others.
is it so wrong, solving the problem like this ?