Created
January 29, 2015 06:53
-
-
Save onproton/80b5a1e83101bae731fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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