Boolean

OliverE

Power member.
Reputation
0
Boolean

Ok so just a few basics, if you dont know what Boolean is, its basically computer speak.
Boolean has two outcomes, 1 or 0. 1 meaning true and 0 meaning false.

  1. Create a new project and class under the name of Boolean
  2. Have a look and try and understand the code using the comments ive included.
  3. Paste the code below into your code view (replacing everything else in there)
  4. Run the program, check the console for the output
  5. Change the value stated in the code and run the program again
  6. Keep doing this until you understand how the program works.
[java]
public class Boolean {

public static void main ( String args [ ] )
{
int bananas = 5; //How many bananas are in stock?
boolean isStock;
if (bananas>=2 && bananas<=12) // If banana stock is greater or equal to 2 AND less than but equal to 12
isStock = true; //Output True
else
isStock = false; //Output False

System.out.println("Correct ammount of bananas in stock? " + isStock); //Output Printed
}
}
[/java]

Now you've sorted that out, try and make the IF statement a bit simpler.
Hint: The else and the line below isnt needed.

PM me your code if you think you've figured it out.
 
For all the people that don't know,

In computers:

1 = true
0 = false

A Boolean is a type that will either return or be equal to true or false. Or 1/0.
 
I did have that at the top of the thread. :/

Ok so just a few basics, if you dont know what Boolean is, its basically computer speak. So its either equal to 1 or 0, True or False.
Light on, Light off :)
 
BleepyEvans said:
I did have that at the top of the thread. :/

Ok so just a few basics, if you dont know what Boolean is, its basically computer speak. So its either equal to 1 or 0, True or False.
Light on, Light off :)

I know, but that sentence makes no sense to me, so I reiterated it just in case anyone else has that problem.

I hope it was okay.
 
Back
Top