Java Datatypes

  • + 0 comments

    JAVA15

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

    public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = Integer.parseInt(sc.nextLine());
        while (t > 0) {
            String str = sc.nextLine();
            try {
                Long.parseLong(str);
                try {
                    Integer.parseInt(str);
                    try {
                        Short.parseShort(str);
                        try {
                            Byte.parseByte(str);
                            System.out.println(str + " can be fitted in:");
                            System.out.println("* byte");
                        } catch(Exception e) {
                            System.out.println(str + " can be fitted in:");
                        }
                        System.out.println("* short");
                    } catch(Exception e) {
                        System.out.println(str + " can be fitted in:");
                    }
                    System.out.println("* int");
                } catch(Exception e) {
                    System.out.println(str + " can be fitted in:");
                }
                System.out.println("* long");
            } catch(Exception e) {
                System.out.println(str + " can't be fitted anywhere.");
            }
            t--;
        }
    }
    

    }