I have been building program, where a. teacher is asked for information of 5. students and all the inputs should be saved after to a txt. file. Although my file is always created but is always empty... Could someone please help me find my mistake ?
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.IOException;
public class programming_project_1 {
public static void main(String[] args) throws IOException
{
int numbersOfLoops = 1;
Scanner scn = new Scanner(System.in);
while (true){
if (numbersOfLoops == 6){
break;
}
System.out.println("First Name: " );
String first_name = scn.next();
System.out.println("Last Name: " );
String last_name = scn.next();
System.out.println("Final Score: ");
int score = scn.nextInt();
numbersOfLoops++ ;
PrintWriter out = new PrintWriter("grades.txt");
System.out.println("First Name: " + first_name);
System.out.println("Last Name: " + last_name);
System.out.println("Final Score: " + score);
out.close();
}
}
}