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.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intn=Integer.parseInt(scanner.nextLine());for(inti=0;i<n;i++){Stringvalue=scanner.nextLine();try{longcurrentNum=Long.parseLong(value);System.out.printf("%s can be fitted in:%n",currentNum);if(currentNum>=Byte.MIN_VALUE&¤tNum<=Byte.MAX_VALUE){System.out.println("* byte");}if(currentNum>=Short.MIN_VALUE&¤tNum<=Short.MAX_VALUE){System.out.println("* short");}if(currentNum>=Integer.MIN_VALUE&¤tNum<=Integer.MAX_VALUE){System.out.println("* int");}if(currentNum>=Long.MIN_VALUE&¤tNum<=Long.MAX_VALUE){System.out.println("* long");}}catch(Exceptione){System.out.printf("%s can't be fitted anywhere.%n",value);}}scanner.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 →