• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!


 
Marshal
Posts: 4475
569
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4475
569
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic