-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputString.java
More file actions
27 lines (26 loc) · 889 Bytes
/
InputString.java
File metadata and controls
27 lines (26 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Sanskar Jadhav AIML B1 PRN 21070126076
public class InputString {
public static void checkIndia(String a) throws NOMATCHEXCP {
// check if string is India
if (!a.equals("India")) {
// if not throw exception
throw new NOMATCHEXCP("You didn't type India!");
}
}
public static void main(String[] args) {
// count variable to find position of word that is wrong
int count = 0;
// loop through all words typed by user
for(String i: args){
try{
checkIndia(i);
count++;
}
catch(NOMATCHEXCP e){
System.err.println("Error caught for word " + (count+1) +" (" + i +")");
// to see line of error with message
e.printStackTrace();
}
}
}
}