Write a method that checks whether a string is a valid password. Suppose the pas
ID: 3640208 • Letter: W
Question
Write a method that checks whether a string is a valid password. Suppose the password rule is as follows. A password must have 8 characters, only letters and at least two digits. Write a program that prompts the User to enter a password and display" valid password " if the is followed or" invalid password " otherwise.
Explanation / Answer
// Here is Your function which takes String(Password ) as an argument and check its validity. public void CheckPassword(String S){ if(S.length()90)&&((int)c < 97))||(((int)c >57)&&((int)c < 65))) { System.out.println("Invalid Password"); return ; } if(((int)c >47)&&((int)c < 58)) { k++; } } if(k < 2) { System.out.println("Invalid Password"); return ; } System.out.println("Valid Password"); } // here is Sample program using this method. import java.util.Scanner; /** * * @author Imran */ public class NewClass1 { public static void main(String args[]){ Solution s = new Solution(); } } class Solution{ public Solution(){ Scanner stdin = new Scanner(System.in); System.out.print("Enter Your Password : "); String S1 = stdin.next(); CheckPassword(S1); } public void CheckPassword(String S){ if(S.length()90)&&((int)c < 97))||(((int)c >57)&&((int)c < 65))) { System.out.println("Invalid Password"); return ; } if(((int)c >47)&&((int)c < 58)) { k++; } } if(k < 2) { System.out.println("Invalid Password"); return ; } System.out.println("Valid Password"); } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.