I am using Java (VSC is my compiler). I try to read through a document that is in the same folder. However, just scanning causes this error:
An error has occured.
java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at Project1.results(Project1.java:66)
at Project1.main(Project1.java:87)
This is my whole code:
public class Project1() {
public void results(String fileName){
double x, y, xc, yc, rad, radius;
int number_of_circles = 0;
try {
Scanner scanner = new Scanner(new BufferedReader(new FileReader(fileName)));
while(scanner.hasNext()) {
x = scanner.nextDouble();
y = scanner.nextDouble();
rad = scanner.nextDouble();
if(rad > 0) {
number_of_circles++;
}
}
}
catch(Exception exception) {
System.err.println("An error has occured.");
exception.printStackTrace();
}
}
public static void main(String args[]){
Project1 P = new Project1();
P.results("Project1.data");
}
}
I tried different files with different values but it does not seem to help. Thanks. I looked at other threads, but they seem to not cover the exact same problem. It looks like if I put only integer values inside Project1.data, then it works, but obviously I want to allow for other values
Project1.data values:
9.50 2.40 3.20
2.20 3.40 5.60
2.50 2.40 3.20
3.20 4.40 5.60