So it took me a while to fix all the errors from debug and run the program I wrote from my intro Java class. But now it is giving me the following error after first input.
Exception in thread "main" java.io.IOException: Stream closed
at sun.nio.cs.StreamDecoder.ensureOpen(StreamDecoder.java:46)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:148)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at StatsDemo.main(StatsDemo.java:54)
I wrote everything below println according to the comments and instructions. But I am not sure what is wrong. It is supposed to ask to enter the file numbers.txt but after I enter the file, it gives me that error.
import java.text.DecimalFormat;
import java.util.Scanner;
import java.io.*;
public class StatsDemo
{
public static void main(String [] args) throws IOException
{
double sum = 0;
int count = 0;
double mean = 0;
double stdDev = 0;
double difference;
DecimalFormat threeDecimals = new DecimalFormat("0.000");
Scanner keyboard = new Scanner (System.in);
String filename;
System.out.println("This program calculates statistics"
+ "on a file containing a series of numbers");
System.out.print("Enter the file name: ");
filename = keyboard.nextLine();
throws IOExceptionfrom yourmainmethod. While it technically allows you to avoidtry/catch, there will never be an entity that you control callingmain, so any exceptions will be unhandled, which is not good coding practice.