<\/span><\/h2>\n\n\n\nThe first line contains an integer, T<\/em><\/strong>, denoting the number of test cases.
Each test case, T<\/em><\/strong>, is comprised of a single line with an integer, n<\/em><\/strong>, which can be arbitrarily large or small.<\/p>\n\n\n\n<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nFor each input variable n <\/em><\/strong>and appropriate primitive datatype<\/em><\/strong>, you must determine if the given primitives are capable of storing it. If yes, then print:<\/p>\n\n\n\n n can be fitted in:\n * dataType<\/code><\/pre>\n\n\n\nIf there is more than one appropriate data type, print each one on its own line and order them by size (i.e.:<\/p>\n\n\n\n
byte < short < int < long ).<\/em><\/strong><\/p>\n\n\n\nIf the number cannot be stored in one of the four aforementioned primitives, print the line:<\/p>\n\n\n\n
n can't be fitted anywhere.<\/code><\/pre>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\n 5\n -150\n 150000\n 1500000000\n 213333333333333333333333333333333333\n -100000000000000<\/code><\/pre>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\n -150 can be fitted in:\n * short\n * int\n * long\n 150000 can be fitted in:\n * int\n * long\n 1500000000 can be fitted in:\n * int\n * long\n 213333333333333333333333333333333333 can't be fitted anywhere.\n -100000000000000 can be fitted in:\n * long<\/code><\/pre>\n\n\n\nExplanation<\/strong><\/p>\n\n\n\n-150<\/strong> can be stored in a short, an int, or a long.<\/p>\n\n\n\n213333333333333333333333333333333333<\/em><\/strong> is very large and is outside of the allowable range of values for the primitive data types discussed in this problem.<\/p>\n\n\n\n<\/span>Solution –<\/strong> Java Datatypes<\/strong><\/span><\/h2>\n\n\n\nimport java.util.*;\nimport java.io.*;\n\nclass Solution{\n public static void main(String []argh)\n {\n Scanner sc = new Scanner(System.in);\n int t=sc.nextInt();\n for(int i=0;i<t;i++)\n {\n try\n {\n long x=sc.nextLong();\n System.out.println(x+\" can be fitted in:\");\n if(x>=-128 && x<=127)System.out.println(\"* byte\");\n if (x>=-32768 && x<=32767)System.out.println(\"* short\");\n if (x>=-2147483648 && x<=2147483647)System.out.println(\"* int\");\n if (x>=-9223372036854775808L && x<=9223372036854775807L)System.out.println(\"* long\");\n }\n catch(Exception e)\n {\n System.out.println(sc.next()+\" can't be fitted anywhere.\");\n }\n\n }\n }\n}\n\n<\/pre>\n\n\n\n