0% found this document useful (0 votes)
4 views

Program Exept i On

Uploaded by

shreyapramod12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Program Exept i On

Uploaded by

shreyapramod12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAM

//
//
import java.lang.*;
import java.util.*;
class Zero{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter first number A");
int A=sc.nextInt();
System.out.println("Enter second number B");
int B=sc.nextInt();
try{
System.out.println(A+" / "+B+" = "+A/B);
}
catch(ArithmeticException e){
System.out.println("printStackTrace() returns : ");
e.printStackTrace();
System.out.println("\nToString() returns : ");
System.out.println(e.toString());
System.out.println("\ngetMessage() returns : ");
System.out.println(e.getMessage());
}

}
}
package AgeExpt;
public class Validity extends Exception{

public void Validity(){


System.out.println("Not Eligible For Voting");
}
}

import java.util.*;
import AgeExpt.*;
class Vote{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the age");
int age=sc.nextInt();
try{
if (age>18 && age<60){
System.out.println("Eligible For Voting");
}
else{
throw new AgeExpt.Validity();
}
}
catch( AgeExpt.Validity e){
e.Validity();
}

}}
import java.lang.*;
import java.util.*;

class ArrayExpt{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int A[]=new int[5];
System.out.println("Enter 5 elements ");
for (int i=0;i<5;i++){
A[i]=sc.nextInt();
}
try{
A[6]=40;
}
catch(ArrayIndexOutOfBoundsException e){
e.printStackTrace();
System.out.println(e.getMessage());

You might also like