JPR 13
JPR 13
class Timepass {
public static void checkAge(int age) throws ArithmeticException {
if (age < 18) {
throw new ArithmeticException("Not eligible to vote");
} else {
System.out.println("Eligible to vote");
}
}
OUTPUT:
OUTPUT:
class StringThrow{
public void getstring() throws NotMatchExceptions{
String strm = "India";
String getstr;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Password: ");
getstr = sc.nextLine();
if(getstr.equals(strm)){
System.out.println("Correct String!!");
}
else{
throw new NotMatchExceptions("String Not Matched!!");
}
}
public static void main(String[] args){
StringThrow obj = new StringThrow();
try{
obj.getstring();
}
catch(NotMatchExceptions e){
System.out.println(e.getMessage());
}
}
}
OUTPUT: