Advertisement
d1i2p3a4k5

20.User defined Exception

Oct 18th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.*;
  2. class notequal extends Exception
  3. {
  4.     void display()
  5.     {
  6.         System.out.println("String are not equal");
  7.     }
  8. }
  9. class stringequal
  10. {
  11.     public static void main(String args[])
  12.     {
  13.         Scanner t = new Scanner(System.in);
  14.         String s1,s2;
  15.         System.out.println("enter 1st string");
  16.         s1 = t.next();
  17.         System.out.println("enter 2nd string");
  18.         s2 = t.next();
  19.         try
  20.         {
  21.             if(s1.equals(s2))
  22.             {
  23.                 System.out.println("Strings are equal");
  24.             }
  25.             else
  26.             {
  27.                 throw new notequal();
  28.             }
  29.         }
  30.         catch(notequal n)
  31.         {
  32.             n.display();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement