+ 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

12th May 2020, 9:43 AM
Muhammad Bilal
Muhammad Bilal - avatar
3 Respuestas
+ 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"); } } }
12th May 2020, 9:46 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
0
Why are you using if(password.matches(".*[0123456789].*)) number++; Twice
12th May 2020, 9:50 AM
Muhammad Bilal
Muhammad Bilal - avatar
0
here are two mistakes, check it for chars 'A' or '0' (zero) if ( ((int) arr[i]>=49) || ((int) arr[i]<=57) )
12th May 2020, 5:03 PM
zemiak