My java code is to read a data text file and output the number of good readings and bad data. Bad data is any non-integer or negative reading. For the non-integer reading, I use nextInt() method to read an integer from the file, if the data is not an integer, InputMismatchException will be thrown. Your program must catch this exception. the exception class is called HRIllegalValueException
import java.io.*;
import java.util.*;
public class DemoEx {
public static void main(String[] args)throws IOException {
Scanner in = new Scanner(new FileReader("HR.txt"));
int badData = 0;
int goodData = 0;
while (in.hasNext()){
try {
int value = in.nextInt();
if(value<0)
else
}
catch(InputMismatchException ex) {
}
}
}
}