I am working on a Java project that looks like a digital time machine, basically saves what happened on a particular server, archives it into a specific file and saves it in a directory somewhere for safe storage. Now I'm working on a password function. I have the basics to check for correctness or incorrectness, but when I enter the wrong answer, the class ends after you say "Invalid password." Is there a way for it to loop from the end of the else to the start of main , so I don't need to re-execute the class every time?
import java.util.Scanner; import java.util.*; public class Adam { public static void main(String args[]) { String passwrd = "password"; String inputPassword; System.out.print("Please Input Password "); Scanner sc = new Scanner(System.in); inputPassword = sc.nextLine(); if (inputPassword.equals(passwrd)) { System.out.println("Password Accepted, Loading Archive..."); } else { System.out.println("Invalid Password"); } } }
source share