Hi! I am new here and currently taking my first CS class, which happens to be Java. Usually I do very well with the assignments and have no trouble, but right now I am completely stumped.
We just learned file input/output and loops, so our assignment is to read 30 scores (integers) from a file and display them using regular output. The only problem is, I'm supposed to use a for loop to only read the first 30 numbers.
So far, I can only get my code to display the first number of the file repeatedly. I am completely stumped!
This is what my code looks like:
import java.util.Scanner; import java.io.*; public class Echo { public static void main(String[] args) throws IOException { int number; int score; File file = new File("scores.txt"); Scanner inputFile = new Scanner(file); score = inputFile.nextInt(); for(number=1; number<=30; number=number+1) {System.out.println(score);} inputFile.close(); } }
I'm sure it has to be something simple that I'm overlooking. Any help is appreciated! Thanks.