error: integer number too large: 2147483648 if(x>-2147483648 x<2147483648 )

Viewed 22

It is showing me the error of value of x and catch without try.

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



class Solution{
  public static void main(String []argh)
  {



      Scanner sc = new Scanner(System.in);
      int t=sc.nextInt();

      for(int i=0;i<t;i++)
      {

          try
          {
              long x=sc.nextLong();
              System.out.println(x+" can be fitted in:");
              if(x>=-128 && x<=127)
              {
                      System.out.println("* byte");
                      System.out.println("* short");
                       System.out.println("* int");
                        System.out.println("* long");
              }
              if(x>-32768 && x<32767)
              {
                      System.out.println("* short");
                      System.out.println("* int");
                        System.out.println("* long");
              }
             else if(x>-2147483648 && x<2147483647 )
              {
                      System.out.println("* int");
                        System.out.println("* long");
              }
             else if(x> -9223372036854775808 && x< -9223372036854775807)
              {
                     System.out.println("* long");  
              }
          catch(Exception e)
          {
              System.out.println(sc.next()+" can't be fitted anywhere.");
          }

      }
  }
}

What is wrong in this code ? I have compared the value of x with the minimum and maximum value of respective data type. It is also showing me the error of catch without try.

0 Answers
Related