Advertisement
Shailrshah

Throwing NoMatchException when Input is not 'India'

Oct 4th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2. class NoMatchException extends Exception{}
  3. class DiffPattern{
  4.     public static void main(String[] args){
  5.         System.out.print("Whitch country is your favorite? -");
  6.         try{
  7.             if(!"India".equals(new Scanner(System.in).next())) throw new NoMatchException();
  8.             else System.out.println("You love your country!");
  9.         } catch(NoMatchException e){
  10.             System.out.println("India should be your favorite!");
  11.         }
  12.     }
  13. }
  14. // Output:-
  15. // Whitch country is your favorite? -The United States of America
  16. // India should be your favorite!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement