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.
- Prepare
- Java
- Introduction
- Java Datatypes
- Discussions
Java Datatypes
Java Datatypes
+ 0 comments import java.util.*;
class Solution {
public static void main(String[] argh) { validateNumber(); } private static void validateNumber() { Scanner sc = new Scanner(System.in); int t = 0; try { t = sc.nextInt(); for (int i = 0; i < t; i++) { try { long x = sc.nextLong(); if (x >= -9223372036854775808L && x <= 9223372036854775807L) { System.out.println(x + " can be fitted in:"); if (x >= -128 && x <= 127) { System.out.println("* byte"); } if (x > -32768 && x <= 32767) { System.out.println("* short"); } if (x > -2147483648 && x <= 2147483647) { System.out.println("* int"); } if (x > -9223372036854775808l && x <= 9223372036854775807l) { System.out.println("* long"); } } } catch (Exception e) { System.out.println(sc.next() + " can't be fitted anywhere."); } } } catch (Exception e) { System.out.println(sc.next() + " Error number please retry."); validateNumber(); } sc.close(); }
}
+ 0 comments import java.util.; import java.io.;
class Solution{ 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"); if(x>= -32768 && x<= 32767) System.out.println("* short"); if(x>= -2147483648 && x<= 2147483647) System.out.println("* int"); if(x>= -9223372036854775808L && x<= 9223372036854775807L) System.out.println("* long"); } catch(Exception e) { System.out.println(sc.next()+" can't be fitted anywhere."); } } }
}
+ 0 comments 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"); } if (x >= -32768 && x <= 32767) { System.out.println("* short"); } if (x >= -2147483648 && x <= 2147483647) { System.out.println("* int"); } if (x >= -9223372036854775808L && x <= 9223372036854775807L) { System.out.println("* long"); } } catch (Exception e) { System.out.println(sc.next() + " can't be fitted anywhere."); } } }
+ 0 comments import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int i=0;i<t;i++){ String in = scan.next(); try{ Long n = Long.parseLong(in); if(n>=Byte.MIN_VALUE && n<=Byte.MAX_VALUE){ System.out.println(in+" can be fitted in:"); System.out.println("* byte\n* short\n* int\n* long"); } else if(n>=Short.MIN_VALUE && n<=Short.MAX_VALUE){ System.out.println(in+" can be fitted in:"); System.out.println("* short\n* int\n* long"); } else if(n>=Integer.MIN_VALUE && n<=Integer.MAX_VALUE){ System.out.println(in+" can be fitted in:"); System.out.println("* int\n* long"); } else{ System.out.println(in+" can be fitted in:"); System.out.println("* long"); } } catch(Exception e){ System.out.println(in+" can't be fitted anywhere."); } } }
}
+ 0 comments import java.util.*; import java.io.*; class Solution{ 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"); //Complete the code if( x >= -Math.pow(2,15) && x <= Math.pow(2,15)-1)System.out.println("* short"); if( x >= -Math.pow(2,31) && x <= Math.pow(2,31)-1)System.out.println("* int"); if( x >= -Math.pow(2,63) && x <= Math.pow(2,63)-1)System.out.println("* long"); } catch(Exception e) { System.out.println(sc.next()+" can't be fitted anywhere."); } } } }
Load more conversations
Sort 1284 Discussions, By:
Please Login in order to post a comment