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.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Control Structures.
2.1 Program Construction In Java
Factorise means put into brackets Solve means Find the values of x which make the equation true.
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
More on Algorithms and Problem Solving
CS&E 1111 ExIFs IFs and Nested IFs in Excel Objectives: Using the If function in spreadsheets Nesting If functions.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
CS0007: Introduction to Computer Programming
Chapter 6 Horstmann Programs that make decisions: the IF command.
Control Flow C and Data Structures Baojian Hua
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
Chapter 4: Control Structures: Selection
The switch Statement, DecimalFormat, and Introduction to Looping
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
Flow of Control Java Programming Mrs. C. Furman January 5, 2009.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
 Java has the logical operators and, or, and not, symbolized by &&, ||, and !, respectively.  Logical or means one or the other or both conditions hold.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
CPS120: Introduction to Computer Science Decision Making in Programs.
PHY281Flow ControlSlide 1 Decisions In this section we will learn how to make decisions in a Java program  if Statements  if... else Statements  Comparison.
Decision Making Selection structures (if....else and switch/case)
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 2. Program Construction in Java. 2.4 Selection (decisions)
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
PROGRAM FLOW CHAPTER3 PART1. Objectives By the end of this section you should be able to: Differentiate between sequence, selection, and repetition structure.
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Conditional Execution Chapter 3 Python for Informatics: Exploring Information
InequalitiesInequalities. An inequality is like an equation, but instead of an equal sign (=) it has one of these signs: Inequalities work like equations,
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
What is a Boolean expression?
Starting Out With Java 5 (Control Structures to Objects) Chapter 3 By Tony Gaddis Copyright © 2005 Pearson Addison-Wesley. All rights reserved.
CONTROL STRUCTURE. 2 CHAPTER OBJECTIVES  Learn about control structures.  Examine relational and logical operators.  Explore how to form and evaluate.
Pascal Programming Making decisions - Selection Statements National Certificate Unit 4 Carl Smith.
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
Decision Statements, Short- Circuit Evaluation, Errors.
Compare and Order Integers SWBAT compare and order integers.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
ECE 122 Feb. 8, if Statement A condition is an expression that can be either true, or false. “if” statement allows a program to make a decision.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
LECTURE # 7 : STRUCTURED PROGRAMMING Selection Statements Tr.Hadeel.
If/Else Statements.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Content Programming Overview The JVM A brief look at Structure
CS0007: Introduction to Computer Programming
WELCOME to….. The If Statement.
Lecture 3- Decision Structures
Operator Precedence Operators Precedence Parentheses () unary
Programming Fundamentals
Lecture 3 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz
Number Line Where are you on the learning journey?
Pages:51-59 Section: Control1 : decisions
Selection Control Structure
Selection Statements.
JavaScript conditional
CS2011 Introduction to Programming I Selections (I)
Program Flow.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
CHAPTER 5: Control Flow Tools (if statement)
Pages:51-59 Section: Control1 : decisions
Presentation transcript:

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

The “if” statement Your 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: program… if( some condition ){ come in here! } program

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!

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”); }

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)

Symbols AND&& OR|| Not!

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)

Now Try A3!