Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If ... else ?

 
podonga poron
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code checks if the notepad is open (windows xp) .. if is open it prints a msg who tell the user "notepad is open" -- but now i have to implement a message who prints if the notepad is not open, the message will be "notepad is close".

I have tryed for hours to do that lol , i tried with "else", but with no luck, i'm a n00b with java, so i hope a little push here ...

cheers ! and thanks



[ May 12, 2008: Message edited by: podonga poron ]
[ May 12, 2008: Message edited by: podonga poron ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
The problem is that you are trying to combine a while loop and an if block. That works until you add an else to it.

Suggest:
  • Set up a boolean variable notepadOpen, and initialise it to false.
  • If you find "notepad" in your search of the processes, set notepadOpen to true.
  • Include !notepadOpen as an additional test for your while-loop continuation.
  • Move your if-else after the end of the while loop.
  • See whether that lot helps
     
    podonga poron
    Ranch Hand
    Posts: 55
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Awright matey !

    now it works !!

    can you add your implementations too ? just to see the code in a right way, for learning you know, thanks
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 48981
    60
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Apart from the inappropriate name for the class, and the inappropriate use of the main method to hold "real" code, you can probably lose quite a lot of it.

    Never say if (myBoolean == false); say if (!myBoolean). And similarly never say if (myBoolean == true).

    Suggest you can reduce your while loop to thisThen close the reader and write the if-else to print the result later.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic