• 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

Code is not working

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Output:

I did this several times and came up with the same result. What is wrong with my code and how do I fix it?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if (started = false) {


This line is missing one crucial character.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:

if (started = false) {


This line is missing one crucial character.



Thank you very much. Why didn't I get an error message from this?
I was missing the "extra" =.
Thanks,
cc11rocks
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some IDEs will flag this as a possible error, but, technically, it's not an error. In the if statement,

if ( x )

x is evaluated as either true or false. In your code, if ( started = false ), in the expression

started = false;

false was assigned to started, and

if ( started )

was evaluated as being either true or false. In this case, I assume it was determined to be false.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, it's bad form to use == to compare booleans to true or false.
And the topic has nothing to do with GUIs, so I shall move it to an appropriate place.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or get in the habit of using Yoda Conditions
if(false=started) will give the error you expect
if(false==started) will then work as desired
see alse
if("".equals(mystring)) and other constant==variable forms.
 
Greenhorn
Posts: 21
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice thread.. i've learned a lot..
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One tip on posting questions...When you simply say "My code doesn't work", it can be extremely hard for folks to know what you mean. Please tell what is is doing (you did that) and what you think it should be doing (that's the part you didn't).

A lot of the time, the code IS working the way it should, but the original poster's idea of how it should work is wrong - and that can't be corrected unless we know what that is.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David O'Meara wrote: . . .
if(false=started) will give the error you expect
if(false==started) will then work as desired
see also
if("".equals(mystring)) and other constant==variable forms.

I personally would ban the use of == or != with true or false as an operand, on either side. But if ("Campbell".equals(name)) is a good idea; you cannot get a NullPointerException from it, however hard you try.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic