• Post Reply Bookmark Topic Watch Topic
  • New Topic

error: incompatible types: int cannot be converted to boolean on a password checker program  RSS feed

 
Richard Scott
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey yall im trying to write a password checker program and thats the error i get. (the final error!) but this one i dont know how to fix. here is my code. any ideas on how to fix would be greatly appreciated!


 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Scott wrote:

Since Password.charAt(x) could only ever equal a single value at any one time, this is equivalent to if (false). Did you mean to use || (or) instead?
 
Richard Scott
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:
Richard Scott wrote:

Since Password.charAt(x) could only ever equal a single value at any one time, this is equivalent to if (false). Did you mean to use || (or) instead?


Ok so that is anouther question i had about this program. im not sure how to write this. what it is supposed to do is check to see if there is a special charater. is there a better way of doing this?
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I was suggesting is that you probably want to use OR rather than AND.

if ((Password.charAt(x) == 32 || Password.charAt(x) == 64 || Password.charAt(x) == 35 ...

With OR, if anyone of tests is true, then the expression evaluates to true. With AND, all tests must must be true for the expression to be true. Since a particular character can only have a single value (at a particular time), the expression will always evaluate to false. For example, it would not be possible for a character to 32 AND 64 at the same time.

 
Richard Scott
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:What I was suggesting is that you probably want to use OR rather than AND.

if ((Password.charAt(x) == 32 || Password.charAt(x) == 64 || Password.charAt(x) == 35 ...

With OR, if anyone of tests is true, then the expression evaluates to true. With AND, all tests must must be true for the expression to be true. Since a particular character can only have a single value (at a particular time), the expression will always evaluate to false. For example, it would not be possible for a character to 32 AND 64 at the same time.



i see what you are saying i fixed it
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Scott wrote: thats the error i get.

It would help if you'd told us what line that error was on.
I'm guessing it's line 48. String.indexOf returns an int, so the return value cannot be used in an if statement.
I think you probably wanted it to be

Note that I have also removed the semi-colon from that line.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!