import java.util.*; class Test { public static void main(String args[]) { try { System.out.println("Enter Password: "); Scanner obj=new Scanner(System.in); String pass= obj.nextLine(); if(!pass.equals("1234")) System.out.println("Authentication Failure"); else System.out.println("Welcome....!!"); } catch (Exception e) { System.out.println(""); } finally { System.out.println("Thank You.........!!!!!"); ...
Define an exception called ‘NotMatchexception’ that is thrown when a string is not equal to ‘India’. Write a java program that uses this exception.
Code: import java.util.Scanner; class NotMatchException extends Exception { public NotMatchException (String str) { System.out.println(str); } } public class StringExc { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter the string : "); String input = scan.nextLine(); try { if(input.equalsIgnoreCase("India")) System.out.println("String matched !!!"); else throw new NotMatchException ("String not matched !!!"); } catch (NotMatchException s) { ...