+ 1
I don't know what's wrong with my java code or what the error message means
The program is supposed to print out the password is valid if it's 8 or more characters and those characters must be letters or numbers and return false if it's less then 8 or has any special characters
11 ответов
+ 2
Thinking you have not used the variable which you defined as character.
+ 1
I think you copied it from a website or somewhere where whitespace is used... Try typing code by yourself and this error will be removed...
0
Plz post your code here too... It will help us in helping you..
0
https://code.sololearn.com/cj5Y6Gsov473/?ref=app
Sorry I meant to do that
0
Okay I'll try that
0
https://code.sololearn.com/cj5Y6Gsov473/?ref=app
It loads now, but doesn't function properly
0
Zoe
You can check the length outside the loop. < 8 -> return false
Inside the loop check if indexof returns -1 -> return false
If the pw passes the loop you can return true.
public static boolean passwordCheck(String password)
{
String letters;
letters= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
if(password.length() < 8) return false;
for(int i =0; i<password.length();i++){
String character= password.substring(i,i+1);
if(letters.indexOf(password.charAt(i)) == -1){
return false;
}
}
return true;
}
0
"https://code.sololearn.com/cj5Y6Gsov473/?ref=app
It loads now, but doesn't function properly”
Hint: You declared the variable ‘character’, but you are not using it.
0
With Denise Roßberg code it now calls passwords with special characters invalid but doesn't recognize password with less than 8 characters as false
0
Zoe
What do you mean? The method returns false if the pw length is < 8.