Created
August 8, 2020 18:31
-
-
Save muralidharan-rade/7e133faef0d7fe443bc0227b30dbff55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
/* Given an input integer, you must determine which primitive data types are capable of properly storing that input. | |
* The first line contains an integer, n, denoting the number of test cases. | |
* Each test case, T, is comprised of a single line with an integer, n, which can be arbitrarily large or small. | |
*/ | |
class PrimitiveDataType { | |
public static void main(String []argh) | |
{ | |
Scanner sc = new Scanner(System.in); | |
int t=sc.nextInt(); | |
for(int i=0;i<t;i++) | |
{ | |
try | |
{ | |
long x=sc.nextLong(); | |
System.out.println(x+" can be fitted in:"); | |
if(x>=-128 && x<=127) { | |
System.out.println("* byte"); | |
System.out.println("* short"); | |
System.out.println("* int"); | |
System.out.println("* long"); | |
} else if(x>=-32768 && x<=32767) { | |
System.out.println("* short"); | |
System.out.println("* int"); | |
System.out.println("* long"); | |
} else if(x>=Integer.MIN_VALUE && x<= Integer.MAX_VALUE) { | |
System.out.println("* int"); | |
System.out.println("* long"); | |
} else if(x>=Long.MIN_VALUE && x<=Long.MAX_VALUE) { | |
System.out.println("* long"); | |
} | |
//Complete the code | |
} | |
catch(Exception e) | |
{ | |
System.out.println(sc.next()+" can't be fitted anywhere."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment