0

write a java program that defines an exception called, no match.exception that is thrown when a string is not equal to india

can any one do that

23rd Nov 2017, 4:40 PM
Sourav Paul
Sourav Paul - avatar
1 Respuesta
+ 1
import java.util.Scanner; class StringMismatchException extends Exception { public StringMismatchException(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 StringMismatchException("String not matched ???"); } catch (StringMismatchException s) { System.out.println(s); } } }
7th Nov 2018, 6:14 AM
PRANTIK KUMAR PATRA
PRANTIK KUMAR PATRA - avatar