Please help with a do--while loop
Hello,
I am very new to java so please excuse me for asking noob questions!
I am trying to create a do--while loop in my program which repeats itself upon user input of y or Y. Here is the code. All help is much appreciated!
-stevo
import java.util.Scanner;
public class myBook
{
public static void main (String[] args)
{
String another = "y", title, author, publisher;
int year;
Scanner scan = new Scanner (System.in);
do
{
System.out.print("Enter book info:\nTitle:");
title = scan.nextLine();
System.out.print("Author:");
author = scan.nextLine();
System.out.print("Publisher:");
publisher = scan.nextLine();
System.out.print("Year:");
year = scan.nextInt();
System.out.println();
Book book1 = new Book(title, author, publisher, year);
System.out.println(book1);
System.out.println();
System.out.print ("Enter another book (y/n)? ");
another = scan.nextLine();
}
while (another.equalsIgnoreCase("y"));
}
}