+ 1
One test case failed password validator
I am using assci code comparison technique but one test case failed https://code.sololearn.com/c12ZN8p1F5XA/?ref=app
3 odpowiedzi
+ 2
This is my solution to it, hope it helps...
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String password = input.next();
int specialchars = 0;
int numbers = 0;
if(password.matches(".*[0123456789].*")) numbers ++;
if(password.matches(".*[0123456789].*")) numbers ++;
if(password.matches(".*[!@#$%&*].*")) specialchars ++;
if(password.matches(".*[!@#$%&*].*")) specialchars ++;
if(numbers == 2 && specialchars == 2 && password.length() >= 7){
System.out.println("Strong");
} else{
System.out.println("Weak");
}
}
}
0
Why are you using
if(password.matches(".*[0123456789].*))
number++;
Twice
0
here are two mistakes, check it for chars 'A' or '0' (zero)
if ( ((int) arr[i]>=49)
|| ((int) arr[i]<=57) )