Java Datatypes

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int test=sc.nextInt();
            while(test -- >0){
                String n=sc.next();
                boolean fit=false;
                try{
                    
                    byte b=Byte.parseByte(n);
                    if(!fit){
                        fit=true;
                        System.out.println(b+" can be fitted in:");
                    }
                    System.out.println("* byte");
                }
                catch(Exception e){}
                try{
                    
                    short b=Short.parseShort(n);
                    if(!fit){
                        fit=true;
                        System.out.println(b+" can be fitted in:");
                    }
                    System.out.println("* short");
                }
                catch(Exception e){}
                try{
                    
                    int b=Integer.parseInt(n);
                    if(!fit){
                        fit=true;
                        System.out.println(b+" can be fitted in:");
                    }
                    System.out.println("* int");
                }
                catch(Exception e){}
                try{
                    
                    long b=Long.parseLong(n);
                    if(!fit){
                        fit=true;
                        System.out.println(b+" can be fitted in:");
                    }
                    System.out.println("* long");
                }
                catch(Exception e){}
             if(!fit){
                System.out.println(n+" can't be fitted anywhere.");
             }   
            }
    }
    }