HackerRank Datatypes

By Clifford Kahn, ago, written in Java.
URL http://pastecode.org/index.php/view/28202925
Download Paste or View RawExpand paste to full width of browser | Change Viewing Options
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Solution{
  5.     public static void main(String []args)
  6.     {
  7.  
  8.         Scanner sc = new Scanner(System.in);
  9.         int t=sc.nextInt();
  10.         int n = t;
  11.  
  12.         for(int i=0;i<n;i++)
  13.         {
  14.  
  15.             try
  16.             {
  17.                 long x=sc.nextLong();
  18.                 System.out.println(x+" can be fitted in:");
  19.                 if(x>=-128 && x<=127)System.out.println("* byte");
  20.                 if(x>=-32768 && x<=32767)System.out.println("* short");
  21.                 if(x>=-2147483648 && x<=2147483647)System.out.println("* int");
  22.                 if(x>=-9223372036854775808L && x<=922337203685477580L)System.out.println("* long");
  23.                 //Complete the code
  24.             }
  25.             catch(Exception e)
  26.             {
  27.                 System.out.println(sc.next()+" can't be fitted anywhere.");
  28.                
  29.             }
  30.  
  31.         }
  32.     }
  33. }

Here you can reply to the paste above

Make Private

   

Feeling clever? Set some advanced options.