This:
numberOfStudents "\n"
isn't valid. You've got two tokens there - an identifier and a string literal - with just a space between them. That's not valid. You could use concatenation:
System.out.printf("Number of students: " + numberOfStudents + "\n");
if you want... but you can't just put the string literal at the end like that.
I would suggest that your final code is the cleanest anyway, although I'd remove the space before the line break. Another alternative would be to let println
put the line break on for you:
System.out.println("Number of students: " + numberOfStudents);