'Why do I get java.lang.IllegalStateException: Scanner closed [closed]
Silly question but I've been receiving this error message and i don't understand the error message. Any help in helping me understand my short comings would be much appreciated
import java.util.Scanner;
public class Exercise9 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter x coordinate for point 1: ");
double x1 = input.nextDouble();
input.close();
System.out.print("Enter y coordinate for point : ");
double y1 = input.nextDouble();
input.close();
System.out.print("Enter x coordinate for point 2: ");
double x2 = input.nextDouble();
input.close();
System.out.print("Enter y coordinate for point 2: ");
double y2 = input.nextDouble();
input.close();
double distance = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
System.out.println("The distance between the two points is" +distance);
}
}
https://pastebin.pl/view/8af98c21
Enter y coordinate for point : Exception in thread "main" java.lang.IllegalStateException: Scanner closed
at java.base/java.util.Scanner.ensureOpen(Scanner.java:1150)
at java.base/java.util.Scanner.next(Scanner.java:1573)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at Exercise9.main(Exercise9.java:12)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
