Skip to content

Instantly share code, notes, and snippets.

@onproton
Created January 29, 2015 06:53
Show Gist options
  • Save onproton/80b5a1e83101bae731fc to your computer and use it in GitHub Desktop.
Save onproton/80b5a1e83101bae731fc to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Validate {
public static void main(String[] args) {
int attempts = 1;
while(attempts<4) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Password: ");
String password = input.next();
if (checkValid(password)) {
System.out.println("Valid Password, Welcome");
}
else {
System.out.println("Invalid Password. " + "attempted " + attempts + "/3");
attempts++;
}
if(attempts==4) {
System.out.println("Sorry, you have used all your password attempts.");
}
}
}
public static boolean checkValid(String password) {
if (password.equals("yes")) {
return true;
}
else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment