Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of.

Slides:



Advertisements
Similar presentations
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advertisements

 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
 Pearson Education, Inc. All rights reserved break and continue Statements Break and continue statements – Alter flow of control break.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
Program Control Dilshad M. Shahid New York
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
 2005 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Control Statements.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1: Selection statements: if, if…else, switch.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
Dale Roberts Introduction to Java - Access Specifiers Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Problem Solving and Control Statements. Using Exit to Terminate Repetition Statements There are many forms of the Exit statement, designed to terminate.
© 2006 Pearson Education 1 Obj: to use compound Boolean statements HW: p.184 True/False #1 – 6 (skip 3)  Do Now: 1.Test your “Charge Account Statement”
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
1 CSCE 1030 Computer Science 1 Control Statements in Java.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
Dale Roberts Program Control using Java - Selection Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Dale Roberts Object Oriented Programming using Java - OOD to OOP: ATM Case Study Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Program Control using Java - Repetition Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
CSC 1051 M.A. Papalaskari, Villanova University Conditional Statements Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Thinking Mathematically
IB Computer Science – Logic
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Relational and Boolean Operators CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Introduction to Java - Input, Program Control and Instantiation Dale Roberts, Lecturer Computer Science, IUPUI
Dale Roberts Object Oriented Programming using Java - Getters and Setters Dale Roberts, Lecturer Computer Science, IUPUI
Control Statements: Part1  if, if…else, switch 1.
ICS102 Lecture 8 : Boolean Expressions King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
 2005 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Chapter 4 Select … Case Multiple-Selection Statement & Logical Operators 1 © by Pearson Education, Inc. All Rights Reserved. -Edited By Maysoon.
 2007 Pearson Education, Inc. All rights reserved Control Statements: Part2.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.-Edited By Maysoon Al-Duwais1.
Object Oriented Programming using Java - Composition
Introduction to Computer Programming
Control Statements: Part 2
Section 7.1 Logical Operators
Chapter 4 C Program Control Part II
Control Statements: Part 2
Control Structures: Part 2
Variable Declaration, Data types, Expressions
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
MSIS 655 Advanced Business Applications Programming
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 6 Control Statements: Part 2
Control Statements: Part 2
Problem Solving and Control Statements
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Discrete Mathematics Lecture 2: Propositional Logic
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Expressions.
Logic of an if statement
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Truth tables Mrs. Palmer.
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Lecture 9: Implementing Complex Logic
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Control Statements:.
Presentation transcript:

Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI

Dale Roberts Logical Operators Logical operators Allows for forming more complex conditions Combines simple conditions Java logical operators && (conditional AND) || (conditional OR) & (boolean logical AND) | (boolean logical inclusive OR) ^ (boolean logical exclusive OR) ! (logical NOT)

Dale Roberts Logical Operators (Cont.) Conditional AND ( && ) Operator Consider the following if statement if ( gender == FEMALE && age >= 65 ) ++seniorFemales; ++seniorFemales; Combined condition is true if and only if both simple conditions are true Combined condition is false if either or both of the simple conditions are false

Dale Roberts 4 Fig | && (conditional AND) operator truth table.

Dale Roberts Logical Operators (Cont.) Conditional OR ( || ) Operator Consider the following if statement if ( ( semesterAverage >= 90 ) || ( finalExam >= 90 ) System.out.println( “Student grade is A” ); System.out.println( “Student grade is A” ); Combined condition is true if either or both of the simple condition are true Combined condition is false if both of the simple conditions are false

Dale Roberts 6 Fig | || (conditional OR) operator truth table.

Dale Roberts Logical Operators (Cont.) Short-Circuit Evaluation of Complex Conditions Parts of an expression containing && or || operators are evaluated only until it is known whether the condition is true or false E.g., ( gender == FEMALE ) && ( age >= 65 ) Stops immediately if gender is not equal to FEMALE

Dale Roberts Logical Operators (Cont.) Boolean Logical AND ( & ) Operator Works identically to && Except & always evaluate both operands Boolean Logical OR ( | ) Operator Works identidally to || Except | always evaluate both operands

Dale Roberts Logical Operators (Cont.) Boolean Logical Exclusive OR ( ^ ) One of its operands is true and the other is false Evaluates to true Both operands are true or both are false Evaluates to false Logical Negation ( ! ) Operator Unary operator

Dale Roberts 10 Fig | ^ (boolean logical exclusive OR) operator truth table.

Dale Roberts 11 Fig | ! (logical negation, or logical NOT) operator truth table.

Dale Roberts 12 Fig | Precedence/associativity of the operators discussed so far.

Dale Roberts Acknowledgements Deitel, Java How to Program