Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Conditions in Java

2 First…Boolean Operators A boolean data type is always true or false. Boolean operators always return true or false For example: (x >y) asks “Is x bigger then y”?

3 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<=yIs x less then or equal to y? x==yIs x equal to y?

4 The “if” statement Your program is going along, and you need to make a decision, a fork in the road… ?

5 The if statement In Java the if statement works like this: program… if( some condition ){ come in here! } program

6 For example if (grade < 50){ c.print(“You fail”); } //the program will only go inside the if block //if the grade is less then 50 Note: Don’t put semicolons on if statements!

7 If else Sometimes you want to specify another path if the condition is not met. For this you would use else. if(grade<50){ c.print(“You fail”); } else{ c.print(“you pass”); }

8 Conjunctives Two conditions can be linked together using conjunctives: AND OR Ex if(4<x AND x<10) Sometimes you want the opposite of a condition, Ex: if ( x is not equal to 4)

9 Symbols AND&& OR|| Not!

10 For example Let 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)

11 Now Try A3!


Download ppt "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."

Similar presentations


Ads by Google