Issue
Hello i am trying to write a method that checks whether a string is a valid password. I Suppose the password rules are as follows: A password must have at least ten characters. A password consists of only letters and digits. A password must contain at least three digits.
I wrote the code but i see this error i don't know why.
package javaapplication6;
import java.util.Scanner;
import javafx.beans.binding.Bindings;
public class JavaApplication6 {
public static boolean isvalidPassword(String nume){
int count = 0;
for(int i=0; i<nume.length();i++){
if(Character.isDigit(nume.charAt(i))){
count++;
}
}
if (count<3){
return false;
}
if (nume.length()<10){
return false;
}
for (int i = 0; i < nume.length(); i++) {
if (!Character.isLetter(nume.charAt(i)charAt(i)) && !Character.isDigit(nume.charAt(i))){
return false; }
}
return true;}
}
Solution
If you look closely at the line
if (!Character.isLetter(nume.charAt(i)charAt(i)) && !Character.isDigit(nume.charAt(i))){
you see, that charAt(i)
is duplicate:
nume.charAt(i)charAt(i)
Remove one of the method calls and you should be fine.
Answered By - dunni