7 ) A.
// Java program to demonstrate Arithmetic Exception
import java.io.*;
import java.util.*;
class ArithmeticException_Demo
public static void main(String args[])
try
int a = 30, b = 0;
int c = a/b; // cannot divide by zero
System.out.println ("Result = " + c);
catch(ArithmeticException e) {
System.out.println ("Can't divide a number by 0");
Output
Can't divide a number by 0
7) b) Java program to demonstrate Number Format Exception
import java.io.*;
import java.util.*;
class NumberFormat_Demo
{
public static void main(String args[])
{
try {
// "akki" is not a number
int num = Integer.parseInt ("akki") ;
System.out.println(num);
}
catch(NumberFormatException e) {
System.out.println("Number format exception");
}
}
}
Output
Number format exception
7) c) Java program to demonstrate Array Index Out Of Bound
Exception
import java.io.*;
import java.util.*;
class ArrayIndexOutOfBound_Demo
{
public static void main(String args[])
{
try{
int a[] = new int[5];
a[6] = 9; // accessing 7th element in an array of
// size 5
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println ("Array Index is Out Of Bounds");
}
}
}
Output
Array Index is Out Of Bounds