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.
importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Stringna="%s can't be fitted anywhere.";Scannersc=newScanner(System.in);sc.nextLine();while(sc.hasNextLine()){Stringnum=sc.nextLine();BooleanpreviouslyCalled=false;Object[]obj=newObject[]{Byte.class,Short.class,Integer.class,Long.class};for(inttype=0;type<4;type++){if(obj[type]==Byte.class){try{BytebyteNum=Byte.parseByte(num);if(!previouslyCalled){System.out.printf("%d can be fitted in:%n",byteNum);previouslyCalled=true;}System.out.println("* byte");}catch(NumberFormatExceptionex){}}elseif(obj[type]==Short.class){try{Shortshortnum=Short.parseShort(num);if(!previouslyCalled){System.out.printf("%d can be fitted in:%n",shortnum);previouslyCalled=true;}System.out.println("* short");}catch(NumberFormatExceptionex){}}elseif(obj[type]==Integer.class){try{intintnum=Integer.parseInt(num);if(!previouslyCalled){System.out.printf("%d can be fitted in:%n",intnum);previouslyCalled=true;}System.out.println("* int");}catch(NumberFormatExceptionex){}}elseif(obj[type]==Long.class){try{longlongnum=Long.parseLong(num);if(!previouslyCalled){System.out.printf("%d can be fitted in:%n",longnum);previouslyCalled=true;}System.out.println("* long");}catch(NumberFormatExceptionex){}}}if(!previouslyCalled){System.out.println(String.format(na,num));}}sc.close();}}
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 →
Here is my sol