This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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!


 
Bartender
Posts: 2038
273
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: 2038
273
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
 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!