Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you kindly check and fix my code please? I cannot get it to work. PLEASE FOLLOW MY CODE STRICTLY WITHOUT CHANGING IT ENTIRELY! Problem:

Could you kindly check and fix my code please? I cannot get it to work. PLEASE FOLLOW MY CODE STRICTLY WITHOUT CHANGING IT ENTIRELY!

Problem: Some websites impose certain rules for passwords. Write a method that checks whether a string is a valid password. Suppose the password rules are as follows: A password must have at least techaracters. A password consists of only letters and digits. A password must contain at least three digits. Write a program that prompts the user to enter a password and displays "Valid Password" if the rules are followed or "Invalid Password" otherwise.

My code:

import java.util.*; public class Exercise06_18 { public static void main(String[] args) { // Create a scanner class Scanner input = new Scanner(System.in); // Prompt the user to enter three integers System.out.println("Please enter a password: "); String password = input.next(); checkPassword(password); } public static void checkPassword(String pass) { int digitCount = 0; boolean passwordCondition = true; if(pass.length() < 10) { passwordCondition = false; } for(int i = 0; i < pass.length(); i++) { if(!(Character.isDigit(pass.charAt(i)))) { passwordCondition = false; } if(!(Character.isLetter(pass.charAt(i)))) { passwordCondition = false; } if((Character.isLetter(pass.charAt(i)))) { passwordCondition = false; digitCount++; } if (digitCount < 3) { passwordCondition = false; } } if(passwordCondition = true) { System.out.println("Valid password. "); } else if(passwordCondition = false) { System.out.println("Invalid password. "); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions