23.1) WRITE A PROGRAM TO ACCEPT A PASSWORD FROM THE USER AND THROW “AUTHENTICATION FAILURE ” EXCEPTION IF THE PASSWORD IS INCORRECT. PROGRAM: import java.util.*; class myException extends Exception { myException(String s) { super(s); } } class pass { public static void main(String args[]) { Scanner s=new Scanner(System.in); String s1=new String ("Nesp"); String s2; System.out.println("Enter the password:"); s2=s.next();
if(s1.equals(s2)) { System.out.println("Login Successfully...!"); } else { try {
throw new myException("Authenification Failure"); } catch(myException me) { System.out.println("Handle Exception"+me); } } } } OUPUT: