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){Scannersc=newScanner(System.in);inttest=sc.nextInt();while(test-->0){Stringn=sc.next();booleanfit=false;try{byteb=Byte.parseByte(n);if(!fit){fit=true;System.out.println(b+" can be fitted in:");}System.out.println("* byte");}catch(Exceptione){}try{shortb=Short.parseShort(n);if(!fit){fit=true;System.out.println(b+" can be fitted in:");}System.out.println("* short");}catch(Exceptione){}try{intb=Integer.parseInt(n);if(!fit){fit=true;System.out.println(b+" can be fitted in:");}System.out.println("* int");}catch(Exceptione){}try{longb=Long.parseLong(n);if(!fit){fit=true;System.out.println(b+" can be fitted in:");}System.out.println("* long");}catch(Exceptione){}if(!fit){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 →