+ 1

Why doesn't work??

Hi everyone, I'm trying the validation password challenge and actually i did it on my laptop, but here it doesn't work and I can't see why, somebody can see the error here? Thanks :) public class Program { boolean isSafe(String cad){ boolean safe=false; String specChar="!@#&*%"; int cont=0; if(cad.length()>=7){ for(int i=0;i<cad.length();i++){ for(int j=0;j<specChar.length();j++){ if(String.valueOf(cad.charAt(i)).equals(String.valueOf(specChar.charAt(j)))){ cont++; } } } if(cont>=2){ safe =true; } } return safe; }

2nd Sep 2022, 11:11 AM
Iván
5 Respuestas
+ 3
In your password : special symbols are @$ But your special symbols string specChar has no $ So cont is 1 only, means it returns false.
2nd Sep 2022, 4:25 PM
Jayakrishna 🇮🇳
+ 5
Main method is missing...!!!!!!!! Pls Save code and share link here...
2nd Sep 2022, 11:15 AM
Jayakrishna 🇮🇳
+ 1
I got the main, i just pasted the 'functional' part of the code The main is public static void main(String[] args) { Program p = new Program(); String password="Hello@$World19"; if(p.isSafe(password)){ System.out.println("Strong"); } else{System.out.println("Weak");} } The problem is that my boolean safe is always false, but i still can't see my mistake. Thank you anyway :)
2nd Sep 2022, 2:15 PM
Iván
+ 1
yeah, i skipped that charachter, but then safe was always true, and that helped me find the mistake!!. I was assigning an specific value to the parameter of my method, so if that variable was strong or weak, it gives every test case the same result, i just needed to introduce the scanner and it works, every test case is correct except for one that is hidden so i can't see why :(. Thank you so much for helping me, i was able to notice the error thanks to you!
3rd Sep 2022, 5:12 PM
Iván
+ 1
Is it solved..? I was examined about your posted contest only... Glad if that helped to solve it.. You're welcome..
3rd Sep 2022, 5:24 PM
Jayakrishna 🇮🇳