Conditions in Java. First…Boolean Operators A boolean data type is always true or false. Boolean operators always return true or false For example: (x

  • Published on

  • View

  • Download

Embed Size (px)


  • Conditions in Java

  • FirstBoolean OperatorsA boolean data type is always true or false.Boolean operators always return true or falseFor example: (x >y) asks Is x bigger then y?

  • Operators in Java

    x > yIs x greater then y?x < yIs x less then y?x>=yIs x greater then or equal to y?x

  • The if statementYour program is going along, and you need to make a decision, a fork in the road?

  • The if statement In Java the if statement works like this:

    programif( some condition ){come in here!}program

  • For exampleif (grade < 50){c.print(You fail);}//the program will only go inside the if block//if the grade is less then 50Note: Dont put semicolons on if statements!

  • If elseSometimes you want to specify another path if the condition is not met.For this you would use else.


  • ConjunctivesTwo conditions can be linked together using conjunctives:

    AND OREx if(4

  • Symbols


  • For exampleLet A and B be two conditions.

    A and B (A && B)A or B (A || B)Not A (!A)Not (A and B) !(A &&B)

  • Now Try A3!


View more >