Question:
Dont understand boolean variable in Java?
barcafan
2009-04-05 19:17:45 UTC
Please help me on the very basics of this variable type. I dont understand how to use it for very basic functions. I just started taking a Java programming class.

It would really help if you gave me some code examples and let me know what is going on.

Please dont give me links to other websites, I have been searching the web for hours and its all over my head. My textbook talks very little about it and the one example it gives is still confusing.

Thank you.
Four answers:
Blackcompe
2009-04-05 20:42:42 UTC
Yes, the only value(s) a boolean variable can hold is true or false.
smittynmv
2009-04-05 19:23:55 UTC
I don't code Java, but a Boolean variable is a simple yes or no. I wish I had some code samples for you....
javoronkov
2016-10-17 11:20:18 UTC
you may desire to declare String message as a field. astonishing now, Java does not know what message is meant to be- you're purely pulling it out of nowhere. you spot up actual the place you have public classification SampleThread extends Applet implements Runnable {     Thread t;     int i; that's you telling Java which you have a variable t that's a Thread and that's shared between all techniques interior the class, and which you have a variable i it is an int and is shared between all techniques interior the class. you may desire to characteristic     String message; there too. * purely as a edge notice- Yahoo solutions shall we us use a limited subset of HTML. in case you decide directly to coach indentation, you may desire to apply a non-breaking area, that's particular by utilising typing  
jojoyohan
2009-04-05 19:24:51 UTC
A variable that is a boolean can have only two states, "true" or "false".



boolean isAvailable = true;

if (isAvailiable) //same thing as (isAvailiable == true)

{

isAvailiable = false;

return true;

}

else return false;


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...