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
    04-Jan-2016

  • View
    222

  • Download
    7

Embed Size (px)

Transcript

  • 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.

    if(grade

  • ConjunctivesTwo conditions can be linked together using conjunctives:

    AND OREx if(4

  • Symbols

    AND&&OR||Not!

  • 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!

Recommended

View more >