Answers for "java instead of giving arithmetic exception gives an error"

2

arithmetic exception

It occurs when there is an error 
in the aritchmatic logic. For 
Example we can't divide int to 0.
In this case it will throw arithmatic
exception and we can handle with
try catch block.(unchecked exception)
Posted by: Guest on January-10-2021
1

arithmetic exception in java

class Example1
{
   public static void main(String args[])
   {
      try{
         int num1=30, num2=0;
         int output=num1/num2;
         System.out.println ("Result: "+output);
      }
      catch(ArithmeticException e){
         System.out.println ("You Shouldn't divide a number by zero");
      }
   }
}
Posted by: Guest on October-15-2020

Code answers related to "java instead of giving arithmetic exception gives an error"

Browse Popular Code Answers by Language