Lesson 38: Conditionals #2 (W11D3)

Size: px
Start display at page:

Download "Lesson 38: Conditionals #2 (W11D3)"

Transcription

1 Lesson 38: Conditionals #2 (W11D3) Balboa High School Michael Ferraro October 28, / 61

2 Do Now In Lesson38/DoNow.java, write a method called isdivisiblebyfour() that takes an int returns the boolean values true or false indicating whether the input value is evenly divisible by 4. Once finished, have main() call isdivisiblebyfour() using the following for() loop: for(int i = 0 ; i <= 100 ; i++) { if ( isdivisiblebyfour(i) ) { System.out.println(i+" is divisible by 4"); } } 2 / 61

3 Aim Students will learn how to perform basic logic operations (and, or, & not) in Java and how Java s order of operations works with respect to relational (e.g., <, <=, &!=) and logical operators. 3 / 61

4 Basic Logic: && (and) How does and work in logic? 4 / 61

5 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) 5 / 61

6 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) Evaluate the value of the boolean expression ( p && q ) when... 6 / 61

7 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) Evaluate the value of the boolean expression ( p && q ) when... 1 p = true, q = true 7 / 61

8 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) Evaluate the value of the boolean expression ( p && q ) when... 1 p = true, q = true 2 p = true, q = false 8 / 61

9 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) Evaluate the value of the boolean expression ( p && q ) when... 1 p = true, q = true 2 p = true, q = false 3 p = false, q = true 9 / 61

10 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) Evaluate the value of the boolean expression ( p && q ) when... 1 p = true, q = true 2 p = true, q = false 3 p = false, q = true 4 p = false, q = false 10 / 61

11 Basic Logic: && (and) How does and work in logic? I work really hard and I get good grades. (p && q) Evaluate the value of the boolean expression ( p && q ) when... 1 p = true, q = true 2 p = true, q = false 3 p = false, q = true 4 p = false, q = false && is true when both operands (inputs) are true. 11 / 61

12 Basic Logic: (or) How does or work in logic? 1 or is also true when both operands are true when using inclusive or 12 / 61

13 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) 1 or is also true when both operands are true when using inclusive or 13 / 61

14 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) Evaluate the value of the expression ( p q ) when... 1 or is also true when both operands are true when using inclusive or 14 / 61

15 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) Evaluate the value of the expression ( p q ) when... 1 p = true, q = true 1 or is also true when both operands are true when using inclusive or 15 / 61

16 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) Evaluate the value of the expression ( p q ) when... 1 p = true, q = true 2 p = true, q = false 1 or is also true when both operands are true when using inclusive or 16 / 61

17 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) Evaluate the value of the expression ( p q ) when... 1 p = true, q = true 2 p = true, q = false 3 p = false, q = true 1 or is also true when both operands are true when using inclusive or 17 / 61

18 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) Evaluate the value of the expression ( p q ) when... 1 p = true, q = true 2 p = true, q = false 3 p = false, q = true 4 p = false, q = false 1 or is also true when both operands are true when using inclusive or 18 / 61

19 Basic Logic: (or) How does or work in logic? I m a slacker or I get good grades. (p q) Evaluate the value of the expression ( p q ) when... 1 p = true, q = true 2 p = true, q = false 3 p = false, q = true 4 p = false, q = false is true when either operand (input) is true. 1 1 or is also true when both operands are true when using inclusive or 19 / 61

20 Examples Predict the output of the following: boolean p = true; //I like to sing boolean q = false; //I like to dance if( p q ) { System.out.println("Perform for us!"); } else { System.out.println("Get off the stage!"); } 20 / 61

21 Examples Predict the output of the following: boolean p = false; boolean q = false; //I like to sing //I like to dance if( p q ) { System.out.println("Perform for us!"); } else { System.out.println("Get off the stage!"); } 21 / 61

22 Examples Predict the output of the following: boolean p = false; boolean q = true; //I like to sing //I like to dance if( p && q ) { System.out.println("Perform for us!"); } else { System.out.println("Get off the stage!"); } 22 / 61

23 Examples Predict the output of the following: boolean p = true; boolean q = true; //I like to sing //I like to dance if( p && q ) { System.out.println("Perform for us!"); } else { System.out.println("Get off the stage!"); } 23 / 61

24 Using and and or Write a boolean expression that evaluates to true when a number is between 0 and 9, inclusive / 61

25 Using and and or Write a boolean expression that evaluates to true when a number is between 0 and 9, inclusive... Restated: true when a number is 0 and 9 25 / 61

26 Using and and or Write a boolean expression that evaluates to true when a number is between 0 and 9, inclusive... Restated: true when a number is 0 and 9 Solution: For a number, n, ( n >= 0 ) && ( n <= 9 ) 26 / 61

27 Using and and or Write a boolean expression that evaluates to true when a number is between 0 and 9, inclusive... Restated: true when a number is 0 and 9 Solution: For a number, n, ( n >= 0 ) && ( n <= 9 ) As used in an if() statement: if ( ( n >= 0 ) && ( n <= 9 ) ) {... } 27 / 61

28 Using and and or Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive Excluding the values 5 and 6, i.e., the number is strictly less than 5 or strictly greater than 6, and equal to neither. 28 / 61

29 Using and and or Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive 2... Restated: true when a number is < 5 or > 6 2 Excluding the values 5 and 6, i.e., the number is strictly less than 5 or strictly greater than 6, and equal to neither. 29 / 61

30 Using and and or Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive 2... Restated: true when a number is < 5 or > 6 Solution: For a number, n, ( n < 5 ) ( n > 6 ) 2 Excluding the values 5 and 6, i.e., the number is strictly less than 5 or strictly greater than 6, and equal to neither. 30 / 61

31 Basic Logic:! (not)! is the not, or negation, operator It flips a boolean s truth value boolean isempty = true; //glass is empty if (! isempty ) { takesip(); } else { refillglass(); } 31 / 61

32 Basic Logic:! (not)! is the not, or negation, operator It flips a boolean s truth value boolean isempty = true; //glass is empty if (! isempty ) { takesip(); } else { refillglass(); }! is referred to as an unary operator 32 / 61

33 Basic Logic:! (not)! is the not, or negation, operator It flips a boolean s truth value boolean isempty = true; //glass is empty if (! isempty ) { takesip(); } else { refillglass(); }! is referred to as an unary operator unary means that it takes one operand the values whose truth value is to be flipped 33 / 61

34 Basic Logic:! (not)! is the not, or negation, operator It flips a boolean s truth value boolean isempty = true; //glass is empty if (! isempty ) { takesip(); } else { refillglass(); }! is referred to as an unary operator unary means that it takes one operand the values whose truth value is to be flipped cf. binary operators like +, -, *, /, %,, etc. 34 / 61

35 Mixing Logical Operators Determine the value of c. boolean a = true; boolean b = false; boolean c = ( a &&!b ); 35 / 61

36 Mixing Logical Operators Determine the value of c. boolean a = true; boolean b = true; boolean c = (!a!b ); 36 / 61

37 Mixing Logical Operators Are things any different now? boolean a = true; boolean b = true; //boolean c = (!a!b ); boolean c =!( a && b ); 37 / 61

38 Mixing Logical Operators Are things any different now? boolean a = true; boolean b = true; //boolean c = (!a!b ); boolean c =!( a && b ); We ll revisit this shortly / 61

39 Revisiting the Example Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive: ( n < 5 ) ( n > 6 ) 39 / 61

40 Revisiting the Example Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive: ( n < 5 ) ( n > 6 ) In other words, true when n is < > n 40 / 61

41 Revisiting the Example Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive: ( n < 5 ) ( n > 6 ) In other words, true when n is < > n Isn t it reasonable to say the following instead? It is not true that n is between 5 and 6, inclusive! ( ( n >= 5 ) && ( n <= 6 ) ) 41 / 61

42 Revisiting the Example Write a boolean expression that evaluates to true when a number is less than 5 or greater than 6, exclusive: ( n < 5 ) ( n > 6 ) In other words, true when n is < > n Isn t it reasonable to say the following instead? It is not true that n is between 5 and 6, inclusive! ( ( n >= 5 ) && ( n <= 6 ) ) both boolean expressions are logically equivalent 42 / 61

43 DeMorgan s Rules The rules are fully described in PS #6, / 61

44 DeMorgan s Rules The rules are fully described in PS #6, Summary: Distribute the negation, swap the and/or 44 / 61

45 DeMorgan s Rules The rules are fully described in PS #6, Summary: Distribute the negation, swap the and/or! ( A B )!A &&!B 45 / 61

46 DeMorgan s Rules The rules are fully described in PS #6, Summary: Distribute the negation, swap the and/or! ( A B )!A &&!B! ( A && B )!A!B 46 / 61

47 DeMorgan s Rules The rules are fully described in PS #6, Summary: Distribute the negation, swap the and/or! ( A B )!A &&!B! ( A && B )!A!B Example: 47 / 61

48 DeMorgan s Rules The rules are fully described in PS #6, Summary: Distribute the negation, swap the and/or! ( A B )!A &&!B! ( A && B )!A!B Example:!( a && b ) 48 / 61

49 DeMorgan s Rules The rules are fully described in PS #6, Summary: Distribute the negation, swap the and/or! ( A B )!A &&!B! ( A && B )!A!B Example:!( a && b )!a!b 49 / 61

50 Second DeMorgan s Example!( ( n >= 5 ) && ( n <= 6 ) ) 50 / 61

51 Second DeMorgan s Example!( ( n >= 5 ) && ( n <= 6 ) )!( n >= 5 )!( n <= 6 ) 51 / 61

52 Second DeMorgan s Example!( ( n >= 5 ) && ( n <= 6 ) )!( n >= 5 )!( n <= 6 )!( n >= 5 )!( n <= 6 ) 52 / 61

53 Second DeMorgan s Example!( ( n >= 5 ) && ( n <= 6 ) )!( n >= 5 )!( n <= 6 )!( n >= 5 )!( n <= 6 ) ( n < 5 ) ( n > 6 ) 53 / 61

54 Java Order of Operations When do we need ()s? When don t we? 54 / 61

55 Java Order of Operations Priority Operator Type Operators highest Pemdas () Unary!,, casts, ++, pemdas pemdas, (also modulo, %) pemdas +, Relational Operators <, <=, >, >=, ==,! = Logical and && lowest Logical or x y 55 / 61

56 Java Order of Operations Let s see if we can simplify some earlier examples / 61

57 Java Order of Operations Let s see if we can simplify some earlier examples... ( n >= 0 ) && ( n <= 9 ) are ()s needed? 57 / 61

58 Java Order of Operations Let s see if we can simplify some earlier examples... ( n >= 0 ) && ( n <= 9 ) are ()s needed? n >= 0 && n <= 9 58 / 61

59 Java Order of Operations Let s see if we can simplify some earlier examples... ( n >= 0 ) && ( n <= 9 ) are ()s needed? n >= 0 && n <= 9 ( n < 5 ) ( n > 6 ) are ()s needed? 59 / 61

60 Java Order of Operations Let s see if we can simplify some earlier examples... ( n >= 0 ) && ( n <= 9 ) are ()s needed? n >= 0 && n <= 9 ( n < 5 ) ( n > 6 ) are ()s needed? n < 5 n > 6 60 / 61

61 HW Complete of PS #6, inclusive The reading for Litvin Ch. 6 is available here. 61 / 61

Lesson 36: for() Loops (W11D1)

Lesson 36: for() Loops (W11D1) Lesson 36: for() Loops (W11D1) Balboa High School Michael Ferraro October 26, 2015 1 / 27 Do Now Create a new project: Lesson36 Write class FirstForLoop: Include a main() method: public static void main(string[]

More information

Lesson 39: Conditionals #3 (W11D4)

Lesson 39: Conditionals #3 (W11D4) Lesson 39: Conditionals #3 (W11D4) Balboa High School Michael Ferraro October 29, 2015 1 / 29 Do Now In order to qualify for a $50k loan, the following conditions must be met: Your annual income must be

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

More information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators: http://www.tutorialspoint.com/ruby/ruby_operators.htm RUBY OPERATORS Copyright tutorialspoint.com Ruby supports a rich set of operators, as you'd expect from a modern language. Most operators are actually

More information

Lesson 10: Quiz #1 and Getting User Input (W03D2)

Lesson 10: Quiz #1 and Getting User Input (W03D2) Lesson 10: Quiz #1 and Getting User Input (W03D2) Balboa High School Michael Ferraro September 1, 2015 1 / 13 Do Now: Prep GitHub Repo for PS #1 You ll need to submit the 5.2 solution on the paper form

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Logic Design: Part 2

Logic Design: Part 2 Orange Coast College Business Division Computer Science Department CS 6- Computer Architecture Logic Design: Part 2 Where are we? Number systems Decimal Binary (and related Octal and Hexadecimal) Binary

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

CMSC201 Computer Science I for Majors

CMSC201 Computer Science I for Majors CMSC201 Computer Science I for Majors Lecture 03 Operators All materials copyright UMBC and Dr. Katherine Gibson unless otherwise noted Variables Last Class We Covered Rules for naming Different types

More information

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

More information

Lesson 26: ArrayList (W08D1)

Lesson 26: ArrayList (W08D1) Lesson 26: ArrayList (W08D1) Balboa High School Michael Ferraro October 5, 2015 1 / 25 Do Now Prepare PS #4a (paper form) for pick-up! Consider the code below for powiter(), an iterative algorithm that

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators ARITHMATIC OPERATORS The assignment operator in IDL is the equals sign, =. IDL uses all the familiar arithmetic operators

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Chapter 4: Basic C Operators

Chapter 4: Basic C Operators Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

More information

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

Flow Control. So Far: Writing simple statements that get executed one after another.

Flow Control. So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow control allows the programmer

More information

Chapter 6 Primitive types

Chapter 6 Primitive types Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question

More information

AP Computer Science A

AP Computer Science A AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

BRANCHING if-else statements

BRANCHING if-else statements BRANCHING if-else statements Conditional Statements A conditional statement lets us choose which statement t t will be executed next Therefore they are sometimes called selection statements Conditional

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

COMP combinational logic 1 Jan. 18, 2016

COMP combinational logic 1 Jan. 18, 2016 In lectures 1 and 2, we looked at representations of numbers. For the case of integers, we saw that we could perform addition of two numbers using a binary representation and using the same algorithm that

More information

CS 117 Fall Compound boolean expressions. Control Statements, Part 2. Using boolean operators. Boolean operators

CS 117 Fall Compound boolean expressions. Control Statements, Part 2. Using boolean operators. Boolean operators CS 117 Fall 2003 Control Statements, Part 2 Compound boolean expressions Sometimes we want to evaluate more complex expressions if age is greater than 30 but less than 65, print out You are an old geezer

More information

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

More information

Lesson 24: Recursive Algorithms #1 (W07D3)

Lesson 24: Recursive Algorithms #1 (W07D3) Lesson 24: Recursive Algorithms #1 (W07D3) Balboa High School Michael Ferraro October 2, 2015 1 / 52 Do Now public static int mysteryfcn(int n) { //precondition: n > 0 int result = 1; while ( n >= 1 )

More information

Lecture 3 Operators MIT AITI

Lecture 3 Operators MIT AITI Lecture 3 Operators MIT AITI - 2004 What are Operators? Operators are special symbols used for mathematical functions assignment statements logical comparisons Examples: 3 + 5 // uses + operator 14 + 5

More information

Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data Arithmetic and Bitwise Operations on Binary Data CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides

More information

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Numerical Data CS 180 Sunil Prabhakar Department of Computer Science Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. Requires that we perform operations

More information

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29 CS 31: Introduction to Computer Systems 03: Binary Arithmetic January 29 WiCS! Swarthmore Women in Computer Science Slide 2 Today Binary Arithmetic Unsigned addition Subtraction Representation Signed magnitude

More information

Operators in java Operator operands.

Operators in java Operator operands. Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

Lesson 7 Part 2 Flags

Lesson 7 Part 2 Flags Lesson 7 Part 2 Flags A Flag is a boolean variable that signals when some condition exists in a program. When a flag is set to true, it means some condition exists When a flag is set to false, it means

More information

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input

More information

If Control Construct

If Control Construct If Control Construct A mechanism for deciding whether an action should be taken JPC and JWD 2002 McGraw-Hill, Inc. 1 Boolean Algebra Logical expressions have the one of two values - true or false A rectangle

More information

Selections. CSE 114, Computer Science 1 Stony Brook University

Selections. CSE 114, Computer Science 1 Stony Brook University Selections CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation If you assigned a negative value for radius in ComputeArea.java, then you don't want the

More information

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016 CS 31: Intro to Systems Binary Arithmetic Kevin Webb Swarthmore College January 26, 2016 Reading Quiz Unsigned Integers Suppose we had one byte Can represent 2 8 (256) values If unsigned (strictly non-negative):

More information

ECEN 468 Advanced Logic Design

ECEN 468 Advanced Logic Design ECEN 468 Advanced Logic Design Lecture 26: Verilog Operators ECEN 468 Lecture 26 Operators Operator Number of Operands Result Arithmetic 2 Binary word Bitwise 2 Binary word Reduction 1 Bit Logical 2 Boolean

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

Operators in C. Staff Incharge: S.Sasirekha

Operators in C. Staff Incharge: S.Sasirekha Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

More information

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 More Tutoring Help The Engineering Peer Tutoring Services (EPTS) is hosting free tutoring sessions

More information

Expressions & Assignment Statements

Expressions & Assignment Statements Expressions & Assignment Statements 1 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements

More information

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I ENGI 1020 - Introduction to Computer Programming M A Y 2 8, 2 0 1 0 R E Z A S H A H I D I Last class Last class we talked about the following topics: Constants Assignment statements Parameters and calling

More information

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output? Arithmetic Operators Section 2.15 & 3.2 p 60-63, 81-89 1 Today Arithmetic Operators & Expressions o Computation o Precedence o Associativity o Algebra vs C++ o Exponents 2 Assigning floats to ints int

More information

5. Selection: If and Switch Controls

5. Selection: If and Switch Controls Computer Science I CS 135 5. Selection: If and Switch Controls René Doursat Department of Computer Science & Engineering University of Nevada, Reno Fall 2005 Computer Science I CS 135 0. Course Presentation

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011

More information

Control Structures in Java if-else and switch

Control Structures in Java if-else and switch Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2016 February 2, 2016 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions

More information

CS Introduction to Data Structures How to Parse Arithmetic Expressions

CS Introduction to Data Structures How to Parse Arithmetic Expressions CS3901 - Introduction to Data Structures How to Parse Arithmetic Expressions Lt Col Joel Young One of the common task required in implementing programming languages, calculators, simulation systems, and

More information

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1 Lecture 9 Reminder: Programming Assignment 3 is due Wednesday by 4:30pm. Exam 1 is on Friday. Exactly like Prog. Assign. 2; no collaboration or help from the instructor. Log into Windows/ACENET. Start

More information

SMS 3515: Scientific Computing. Sem /2015

SMS 3515: Scientific Computing. Sem /2015 s s SMS 3515: Scientific Computing Department of Computational and Theoretical Sciences, Kulliyyah of Science, International Islamic University Malaysia. Sem 1 2014/2015 The if s that are conceptually

More information

Department of Computer Science

Department of Computer Science Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and

More information

ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

More information

Expressions and Assignment Statements

Expressions and Assignment Statements Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation, need to be familiar with

More information

CS Programming I: Branches

CS Programming I: Branches CS 200 - Programming I: Branches Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2018 TopHat Sec 3 (AM) Join Code: 925964 TopHat Sec 4 (PM) Join Code: 259495 Boolean Statements

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7. Expressions and Assignment Statements ISBN Chapter 7 Expressions and Assignment Statements ISBN 0-321-33025-0 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

More information

Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

More information

Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide

Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide Second Year Edition Name: Tutorial Group: Groovy can be obtained freely by going to http://groovy-lang.org/download Page 1 of 8 Variables Variables

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups: JAVA BASIC OPERATORS http://www.tuto rialspo int.co m/java/java_basic_o perato rs.htm Copyrig ht tutorialspoint.com Java provides a rich set of operators to manipulate variables. We can divide all the

More information

Programming for Engineers Iteration

Programming for Engineers Iteration Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

More information

Computational Expression

Computational Expression Computational Expression Conditionals Janyl Jumadinova 10 October, 2018 Janyl Jumadinova Computational Expression 10 October, 2018 1 / 16 Computational Thinking: a problem solving process Decomposition

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 Announcements Slides will be posted before the class. There might be few

More information

Comparing Data. Comparing Floating Point Values. Comparing Float Values. CS257 Computer Science I Kevin Sahr, PhD

Comparing Data. Comparing Floating Point Values. Comparing Float Values. CS257 Computer Science I Kevin Sahr, PhD 1 CS257 Computer Science I Kevin Sahr, PhD Lecture 6: Comparing Data and Complex Boolean Expressions Comparing Data 2 When comparing data it's important to understand the nuances of certain data types

More information

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows: STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The

More information

CT 229. Java Syntax 26/09/2006 CT229

CT 229. Java Syntax 26/09/2006 CT229 CT 229 Java Syntax 26/09/2006 CT229 Lab Assignments Assignment Due Date: Oct 1 st Before submission make sure that the name of each.java file matches the name given in the assignment sheet!!!! Remember:

More information

Boolean Algebra Boolean Algebra

Boolean Algebra Boolean Algebra What is the result and type of the following expressions? Int x=2, y=15; float u=2.0, v=15.0; -x x+y x-y x*v y / x x/y y%x x%y u*v u/v v/u u%v x * u (x+y)*u u / (x-x) x++ u++ u = --x u = x -- u *= ++x

More information

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Java enum, casts, and others (Select portions of Chapters 4 & 5) Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

More information

STUDENT LESSON A14 Boolean Algebra and Loop Boundaries

STUDENT LESSON A14 Boolean Algebra and Loop Boundaries STUDENT LESSON A14 Boolean Algebra and Loop Boundaries Java Curriculum for AP Computer Science, Student Lesson A14 1 STUDENT LESSON A14 Boolean Algebra and Loop Boundaries INTRODUCTION: Conditional loops

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Relational and Logical Statements

Relational and Logical Statements Relational and Logical Statements Relational Operators in MATLAB A operator B A and B can be: Variables or constants or expressions to compute Scalars or arrays Numeric or string Operators: > (greater

More information

More Programming Constructs -- Introduction

More Programming Constructs -- Introduction More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

More information

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. and Java. Chapter 2 Primitive Data Types and Operations

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. and Java. Chapter 2 Primitive Data Types and Operations Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter p 1 Introduction to Computers, p, Programs, g, and Java Chapter 2 Primitive Data Types and Operations Chapter

More information

Chapter 7. Expressions and Assignment Statements

Chapter 7. Expressions and Assignment Statements Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

CS1150 Principles of Computer Science Boolean, Selection Statements

CS1150 Principles of Computer Science Boolean, Selection Statements CS1150 Principles of Computer Science Boolean, Selection Statements Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 Math Center https://www.uccs.edu/mathcenter/schedules

More information

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

More information

L05 - Negating Statements

L05 - Negating Statements L05 - Negating Statements CSci/Math 2112 15 May 2015 1 / 14 Assignment 1 Assignment 1 is now posted Due May 22 at the beginning of class Can work on it in groups, but separate write-up Don t forget your

More information

Lesson 12: OOP #2, Accessor Methods (W03D4)

Lesson 12: OOP #2, Accessor Methods (W03D4) Lesson 12: OOP #2, Accessor Methods (W03D4) Balboa High School Michael Ferraro September 3, 2015 1 / 29 Do Now In your driver class from last class, create another new Person object with these characteristics:

More information

C/C++ Programming Lecture 7 Name:

C/C++ Programming Lecture 7 Name: 1. The increment (++) and decrement (--) operators increase or decrease a variable s value by one, respectively. They are great if all you want to do is increment (or decrement) a variable: i++;. HOWEVER,

More information

4. Number Representations

4. Number Representations Educational Objectives You have a good understanding how a computer represents numbers. You can transform integers in binary representation and perform computations. You understand how the value range

More information

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington Selection s CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1 Book reference Book: The practice of Computing Using Python 2-nd edition Second hand book

More information

Logical and Bitwise Expressions

Logical and Bitwise Expressions Logical and Bitwise Expressions The truth value will set you free. 1 C Numbers and Logic Logic deals with two values: True and False Numbers have many values In C, zero is interpreted as logically False

More information

Lecture Notes on Binary Decision Diagrams

Lecture Notes on Binary Decision Diagrams Lecture Notes on Binary Decision Diagrams 15-122: Principles of Imperative Computation William Lovas Notes by Frank Pfenning Lecture 25 April 21, 2011 1 Introduction In this lecture we revisit the important

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003 Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

More information

A Java program contains at least one class definition.

A Java program contains at least one class definition. Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

More information

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Motivation In the programs we have written thus far, statements are executed one after the other, in the order in which they appear. Programs often

More information