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.
- Create a new project and class under the name of Boolean
- Have a look and try and understand the code using the comments ive included.
- Paste the code below into your code view (replacing everything else in there)
- Run the program, check the console for the output
- Change the value stated in the code and run the program again
- Keep doing this until you understand how the program works.
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.