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
1 Antwort
+ 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);
}
}
}