coffeebeforecode

jahnaviJavaException

Feb 26th, 2022 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Jahnavi20BCE0413 {
  4.    
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         Scanner ReadInput = new Scanner(System.in);
  8.         System.out.println("Input Registration number:");
  9.         String reg = ReadInput.nextLine();
  10.         try {
  11.             if (reg.equals("20BCE0413")) {
  12.                 throw new RegNumException();
  13.             }
  14.             System.out.println("Valid Registration number");
  15.         }
  16.         catch(RegNumException e) {
  17.             System.out.println("Invalid Registration number");
  18.         }
  19.         ReadInput.close();
  20.     }
  21. }
  22.  
  23. class RegNumException extends Exception{
  24.    
  25. }
Add Comment
Please, Sign In to add comment