Java End-of-file

  • + 1 comment

    Your for loop can be simplified:

    // For loop 
    public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       for(int i = 1; scan.hasNext(); i++){
           System.out.println(i + " " + scan.nextLine());
       }
    }
    

    You don't have to use the == operator to compare with true since the hasNext method returns a boolean.