Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would one write a program in Java that checks whether a string is a valid pa

ID: 3623029 • Letter: H

Question

How would one write a program in Java that checks whether a string is a valid password? The password must have at least eight characters, must consists of only letters and digits, and must contain at least two digits. The program must prompt the user to enter a password and display "valid password" if the rule is followed or "invalid password" if not.

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"); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote