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.*;publicclassDataTypesExample{publicstaticvoidmain(String[]args){longa;Scannersc=newScanner(System.in);intnumOfQueries=Integer.parseInt(sc.nextLine());long[]nums=newlong[numOfQueries];for(longk:nums){try{nums[(int)k]=sc.nextLong();a=nums[(int)k];if(a>=-128&&a<=127)//*** byte range is -128 to 127{System.out.println(a+" can be fitted in: ");System.out.println("* byte\n* short\n* int\n* long");}elseif(a>=-32768&&a<=32767)//*** short range is -32768 to 32767{System.out.println(a+" can be fitted in: ");System.out.println("* short\n* int\n* long");}elseif(a>=-2147483648&&a<=2147483647)//*** int range is -2147483648 to 2147483647{System.out.println(a+" can be fitted in: ");System.out.println("* int\n* long");}elseif(a>=-9223372036854775808L&&a<=9223372036854775807L)//*** long range is -9223372036854775808// to 9223372036854775807{System.out.println(a+" can be fitted in: ");System.out.println("* long");}else{thrownewException("test");}}catch(Exceptione){System.out.println(sc.nextLine()+" can't be fitted anywhere.");}}}}
Java Datatypes
You are viewing a single comment's thread. Return to all comments →