What is program logic behind the above pgm.In the getBoolean(), we are checking whether the number is generated randomly is zero. If so, we return false elase we return true. Correct me, if i am wrong.
Whether the if statment returns the boolean expr. that is if(boolean) is possible in java. I think I am messing up something?
This particular conditional statement does nothing. The clue as to why is in bold. (It shouldn't even compile). [ August 11, 2005: Message edited by: Paul Sturrock ]
What is program logic behind the above pgm.In the getBoolean(), we are checking whether the number is generated randomly is zero. If so, we return false elase we return true. Correct me, if i am wrong.
Whether the if statment returns the boolean expr. that is if(boolean) is possible in java. I think I am messing up something?
(int) (Math.random() * 2) will return either 0 or 1, therefore having getBoolean() return true or false depending on the returned value is simple a way of generating a random boolean value.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
In the getBoolean(), we are checking whether the number is generated randomly is zero. If so, we return false; else we return true. Correct me, if i am wrong.
true.
Whether the if statment returns the boolean expr. that is if(boolean) is possible in java.
"if (boolean)" is not only possible in Java, it is the only way to write an if statement. "if (0)" (or any other int) will not compile.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens: