0

Trying to figure this out. Learning in Java and not sure how to code this

Write a program that prompts the user to enter a password and displays Valid Password if the rules are followed or Invalid Password other wise. 1. A Password must have at least eight characters. 2. A Password consists of only letters and digits. 3. A Password must contain at least two digits. Write a method that checks whether a string is a valid password.

27th Nov 2018, 12:28 AM
Carlye
Carlye  - avatar
2 Respuestas
+ 13
● take the input as String str ● make a method which returns true if all conditions satify ● rough structure of method 1) str.length() == 8 //if true then continue to 2) else return false 2) then check for number of digits //use ASCII value for it , also count number of digit there using a counter variable //if number of digits >=2 then continue to 3) else returnfalse 3) now run loop again on that String & check for 8-(number if digits) must be the number of alphabets //return true if 3) also return returns true , else false //check out this ASCII code for getting idea of range to be used for alphabets & digits https://code.sololearn.com/c92zC0xH0AHv/?ref=app
27th Nov 2018, 2:50 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
0
you also can use specific regular expressions for checking. For example: String expr ="expression"; Pattern patt = Pattern.compile(expr); Matcher m = patt.matcher("some string"); then you can get boolean value wich you can check in condition block if(){} boolean b = matcher.matches(); you can look example of using in following code: https://code.sololearn.com/ci5m428JvUf9/?ref=app
27th Nov 2018, 12:32 PM
Pavel Zubakha
Pavel Zubakha - avatar