Professional Documents
Culture Documents
Exception Handling
Exception Handling
Exception Handling
ENROLLMENT: 02-132212-036
EXAMPLE:
SOLUTION:
package exception;
try{
int a=10;
int b=0;
int c= a/b;
catch(ArithmeticException e)
}
}
RESULT:
a) Even or odd
SOLUTION:
package exception;
import java.util.Scanner;
else
}}
RESULT:
b) Prime or not
SOLUTION:
package arithmeticexception_demo;
int i,m=0,flag=0;
m=a/2;
if(a==0||a==1)
else
for(i=2;i<=m;i++)
if(a%i==0)
flag=1;
break;
if(flag==0)
}
}
RESULT:
SOLUTION:
package exception;
try
a[10]=1;
catch(ArrayIndexOutOfBoundsException e)
}
}}
RESULT:
3. Write a program that count how many prime numbers between minimum and maximum values
provided by user. If minimum value is greater than or equal to maximum value, the program should
throw a InvalidRange exception and handle it to display a message to the user on the following
format:Invalid range: minimum is greater than or equal to maximum.
SOLUTION:
package exception;
int a= 13;
int i,m=0,flag=0;
m=a/2;
else
{
for(i=2;i<=m;i++)
if(a%i==0)
flag=1;
break;
}}
RESULT: