public class Diary {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
PrintWriter output = null;
try {
output = new PrintWriter (new FileOutputStream("diaryLog"));
} catch (FileNotFoundException e) {
System.out.println("File not found");
System.exit(0);
}
//Ok, I will ask the date for you here:
System.out.println("Enter the date as three integers separated by spaces (i.e mm dd yyyy):");
int month = input.nextInt();
int day = input.nextInt();
int year = input.nextInt();
//And print it in the file
output.println("Date: " + month +"/" + day + "/" + year);
System.out.println("Begin your entry:");
String entry= input.next();
while("end".equals(entry))
{
output.print(entry + " ");
}
output.close();
System.out.println("End of program.");
}
}
The goal of this program is to take input and create a diary entry and output the input to a file when the word end is inputed. When I compile the program does not terminate when I input end and my diary entry is not saved in the output file.