How to make program restart without writing java programname, again.
Currently ive just started a programming course, and well with the stuff i know now i have the start of like a mini text based game, however i want to know how to restart the program if the player takes a wrong turn. Heres the code, and ill say where it is i want the program to restart. thanks
import java.util.*;
public class Adventure
{
public static void main(String[] args)
{
Scanner myKeyboard = new Scanner(System.in);
String answer;
String tryAgain;
System.out.println("Welcome to Adventure!");
System.out.println("Left or Right?: ");
answer = myKeyboard.next();
if ( answer.equals("Left"))
{
System.out.println("You took a wrong turn, try again");
System.out.println("Try Again? Y or N: ");
tryAgain = myKeyboard.next();
}
if ( answer.equals("Right"))
{
System.out.println("You took the correct turn, please Continue!");
System.out.println("Left or Right?: ");
}
else
{
System.out.println("Wrong Data Input");
}
}
}
It is at System.out.println("Try Again? Y or N: ");
tryAgain = myKeyboard.next();
that i wanted to be able to make it go from the start of the program again, instead of inputting the program again, basically like a restart command. anyone help?
thanks