I'm working on creating a program called golf that reads data from a text file. I must be creating it in the wrong way but I don't know how to proceed at this point. I could use some help understanding whats going?
The compiling error says:
Golf.java:9: class golf is public, should be declared in a file named golf.java
public class golf
^
1 error
Code:import java.util.Scanner; import java.io.*; public class golf { public static void main (String[] args) throws IOException { int p1score=0, p2score=0, p3score=0, p4score=0, par=0; int hole=0; String strokes; Scanner fileInput, strokesScan; fileInput = new Scanner(new File("scores.txt")); // Read and process each line of the file while ( fileInput.hasNext() ) { strokes = fileInput.nextLine(); System.out.print ("Strokes: " + strokes); strokesScan = new Scanner (strokes); strokesScan.useDelimiter(""); while (strokesScan.hasNext()) System.out.print (" " + fileInput.next()); System.out.println(); } } }




Reply With Quote