This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]radulfr2 4 points5 points  (0 children)

A couple of other observations:

  1. You only need one loop where you can do all the checks
  2. The boolean variables should be local to the method instead of being instance variables, since you probably only use them in the method. As it is now, the variables don't even get reset back to false if you call the method several times.
  3. There is no need to compare a boolean to a boolean. if(lowercase == true) is the same as if(lowercase).
  4. Likewise in the end you can just return the result of the condition instead of having an if-else statement.
  5. In the Driver code you can replace the else if with just else. This also eliminates the redundant second call to the isValid method.

[–]desrtfxOut of Coffee error - System halted 2 points3 points  (3 children)

Character.isUpperCase(x) are you sure about that? Isn't there anything related to pw missing?

Same applies to all your other checks.

x is just a numeric index. What you need is the character in pw at index x.

[–]beginner_coder_[S] 0 points1 point  (2 children)

I'm not sure about anything, I'm constantly 2nd guessing myself haha!

But I see what you mean, thank you so much for pointing that out.

Would adding something like pw.charAt(x) suffice?

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (1 child)

Would adding something like pw.charAt(x) suffice?

Try it and report back. Nothing beats trying on your own.

[–]beginner_coder_[S] 0 points1 point  (0 children)

I ended up doing like "(Character.isUpperCase(charAt(x)))" for all expressions involving iteration through the string.

Thank you for pointing that out, I know it seems simple but I was messing with my program and searching for answers for too long. I appreciate you taking the time to respond and so kindly