Java Datatypes

  • + 1 comment

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
    
        for (int i = 0; i <= n - 1; i ++){
    
            try{
    
                long number = input.nextLong();
    
                System.out.println(String.format("%d can be fitted in:" ,number));
    
                if ((number >= -128) && (number <= 127)){
                    System.out.println("* byte");
                }
    
                if ((number >= -32768) && (number <= 32767)){
                    System.out.println("* short");
                }
    
                if ((number >= -Math.pow(2,31)) && (number <= (Math.pow(2,31) - 1))) {
                    System.out.println("* int");
                }
    
                if ((number >= -Math.pow(2,63)) && (number <= (Math.pow(2,63) - 1))) {
                    System.out.println("* long");
                }
    
            }
            catch(Exception e){
                System.out.println(input.next() + " can't be fitted anywhere.");
            }
        }
    }
    

    }