SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Luen Hong Wuan wrote:Ankit >>
Boolean has been set as false in default , thus "ok!=false" will return "true" no?
The reason why i set a boolean is because i assumed the program to stop and allow the users to try 3 times. Without the booleans , the program will only allow the user to try once, and the program pops up 3 error messages consequently instead of one, and then exits.
Narendira Sarma wrote:In your code posted above, you are displaying the Error message after each combination is checked from the text file.
Instead of showing the Error message in the else part, you can have a boolean variable assigned to false. If a match is found assign the boolean as true.
After the while loop finishes, check for the boolean and if it is false, display the Error message. This way you will display the error message only once.
Hope I am clear. I will write something like below.
Peter Granstrom wrote:
Hi i liked your answer,
but i think in the if() i would try to decide if boolean to true or false before
because then you dont have to make changes afterwards and can decide
before if its right or wrong and probably get a better structure in your code
Narendira Sarma wrote:
Peter Granstrom wrote:
Hi i liked your answer,
but i think in the if() i would try to decide if boolean to true or false before
because then you dont have to make changes afterwards and can decide
before if its right or wrong and probably get a better structure in your code
Hi Peter,
I couldn't understand what you were trying to say. I am a rookie programmer myself. That being said, I showed him how "I" would have handled the situation.
But I am eager to learn. Could you please tell me more clearly?
Thanks
-Naren
Don't get me started about those stupid light bulbs. |