Java Datatypes

  • + 0 comments

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

    public class Solution {

    public static void main(String[] args) {
            Scanner scn = new Scanner(System.in);
    
            int t = scn.nextInt();
            while (t != 0) {
                    try {
                            long num = scn.nextLong();
                            System.out.println(num + " can be fitted in:");
                            if (num >= -128 && num <= 127) {
                                    System.out.println("* byte\n* short\n* int\n* long");
                            } else if (num >= -Math.pow(2, 15) 
                                                    && num <= Math.pow(2, 15) - 1) {
                                    System.out.println("* short\n* int\n* long");
                            } else if (num >= -Math.pow(2, 31)
                                                    && num <= Math.pow(2, 31) - 1) {
                                    System.out.println("* int\n* long");
                            } else {
                                    System.out.println("* long");
                            }
                    } catch (Exception e) {
                            System.out.println(scn.next() + " can't be fitted anywhere.");
                    }
                    t--;
            }
    
            scn.close();
    }
    

    }