Here is a simple version without any loops. How can I make it loop like "Wrong password. Try again." until user puts the right password instead stopping the program (or give them 3 chances before it stops)?
import java.util.Scanner;
public class helloworld2
{
public static void main(String[] arg)
{
Scanner q = new Scanner(System.in);
long Pass;
boolean auth = true;
System.out.println("Enter Password :");
Pass = q.nextLong();
if ( Pass != 1234 )
{
System.out.println("Wrong Password!");
auth = false;
}
else
{
System.out.println("Password Confirmed.");
auth = true;
}
if (auth) {
////blablabla
}
else
{
return;
}
}
}
do-whileloop.Pass) That's for class names.