Implement Exception handling using Java



Write a program in Java to implement Exception
handling





Program:


class Sk24


 {


  public static void main(String args[ ])


   {


    int a=60,b;


    for (int i=5;i>=0;i--)


         {


           try{


                 b=a/i;


                 System.out.println("Output:"+b);


                }


           catch(ArithmeticException e)


                {


                 
System.out.println("Divide By Zero");


                }


         }


    }


  }


   


     





Compile:


D:\>javac
Sk24.java


Run:


D:\>java Sk24





Output:


Output:12


Output:15


Output:20


Output:30


Output:60


Divide By Zero






















Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C