Hacker rank java 8th problem silution

8.Java Datatypes


import java.util.*; 

class papa{
   public static void main(String args[]){
     Scanner sn = new Scanner(System.in);
  long n = sn.nextLong();
     for( long i=0;i<n;i++){
  try{
      long  x= sn.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>=-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(sn.next() + " can't be fitted anywhere.");
     }
   
     }
   }
 }


Compiler Message
Success
Input (stdin)Download
5
-150
150000
1500000000
213333333333333333333333333333333333
-100000000000000
Expected OutputDownload
-150 can be fitted in:
* short
* int
* long
150000 can be fitted in:
* int
* long
1500000000 can be fitted in:
* int
* long
213333333333333333333333333333333333 can't be fitted anywhere.
-100000000000000 can be fitted in:
* long


Comments

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions