Java Datatypes

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = Integer.parseInt(scanner.nextLine());
            for (int i = 0; i < n; i++) {
                String value = scanner.nextLine();
                try {
                    long currentNum = Long.parseLong(value);
                    System.out.printf("%s can be fitted in:%n", currentNum);
                    if (currentNum >= Byte.MIN_VALUE && currentNum <= Byte.MAX_VALUE) {
                        System.out.println("* byte");
                    }
                    if (currentNum >= Short.MIN_VALUE && currentNum <= Short.MAX_VALUE) {
                        System.out.println("* short");
                    }
                    if (currentNum >= Integer.MIN_VALUE && currentNum <= Integer.MAX_VALUE) {
                        System.out.println("* int");
                    }
                    if (currentNum >= Long.MIN_VALUE && currentNum <= Long.MAX_VALUE) {
                        System.out.println("* long");
                    }
                } catch (Exception e) {
                    System.out.printf("%s can't be fitted anywhere.%n", value);
                }
            }
            
            
            scanner.close();
        }
    }