I have the following Java program. It compiles correctly; however, I get the fol
ID: 3528693 • Letter: I
Question
I have the following Java program. It compiles correctly; however, I get the following error at run-time: Change option to execute implicit classes; can not find explicit application or applet. How do I fix this error? import java.io.FileReader; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.io.IOException; import java.util.Scanner; /** Reads a data set from a file. The file must have the format numberOfValues value1 value2 ... */ public class Initial_Value { /* Reads a data set. @param filename the name of the file holding the data @return the data in the file */ public double[] readFile(String filename) throws IOException, BadDataException { FileReader reader = new FileReader("c:\Users\Robert\April2012\Java\Initial_Value\Initial_Value.data"); try { Scanner in = new Scanner(reader); readData(in); } finally { reader.close(); } return data; } /* Reads all data. @param in the scanner that scans the data */ private void readData(Scanner in) throws BadDataException { if(!in.hasNextInt()) throw new BadDataException("Length expected"); int numberOfValues = in.nextInt(); data = new double[numberOfValues]; for (int i = 0; i < numberOfValues; i++) readValue(in, i); if (in.hasNext()) throw new BadDataException("End of file expected"); } /* Reads one data value @param in the scanner that scans the data @param i the position of the value to read */ private void readValue(Scanner in, int i) throws BadDataException { if(!in.hasNextDouble()) throw new BadDataException("Data value expected"); data[i] = in.nextDouble(); System.out.println("The value is " + data[i] + " ."); } private double[] data; }Explanation / Answer
Please rate with 5 stars :)
You can use this program to read and write files :)