With Assignment Operator

Slides:



Advertisements
Similar presentations
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Advertisements

Flow of Control (1) : Logic Clark Savage Turner, J.D., Ph.D. Some lecture slides have been adapted from those developed.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
1 Shortcuts for Lazy Programmers! Topics Increment and Decrement Operators Assignment Operators.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Expressions, Data Conversion, and Input
LESSON 6 – Arithmetic Operators
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
Java Software Solutions Lewis and Loftus Chapter 5 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. More Programming Constructs.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
Lesson - 7. Operators There are three types of operators: Arithmetic Operators Relational and Equality Operators Logical Operators.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
© 2006 Pearson Education 1 Obj: to use assignment operators HW: Prelab Exercises 2 Quiz 3.1 – 3.4 in two class days  Do Now: 1.Read p.144 – 145 (3.4 “more.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Lecture 5 More Programming Constructs Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Doing math In java.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
Data and Expressions. Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Expressions.
Chapter 7: Expressions and Assignment Statements
Side Effect Operators Changing the value of variables
Java Primer 1: Types, Classes and Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Relational Operations
Chapter 7: Expressions and Assignment Statements
Arithmetic operations & assignment statement
Data Conversion & Scanner Class
Multiple variables can be created in one declaration
Assignment and Arithmetic expressions
Creating Objects & String Class
Type Conversion, Constants, and the String Object
Arithmetic Operator Operation Example + addition x + y
Escape Sequences What if we wanted to print the quote character?
Increment and Decrement
Lecture 3 Expressions Richard Gesick.
Arithmetic Expressions & Data Conversions
Chapter 3: Program Statements
Expressions and Assignment
Assignment Operators Topics Increment and Decrement Operators
Data Types and Expressions
Operators In Java Programming By Rajanikanth B.
Chap 7. Advanced Control Statements in Java
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Data Types and Expressions
Assignment Operators Topics Increment and Decrement Operators
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Arithmetic Expressions & Data Conversions
Data Types and Expressions
Presentation transcript:

With Assignment Operator Increment & Decrement With Assignment Operator

Increment and Decrement The increment and decrement operators are arithmetic and operate on one operand The increment operator (++) adds one to its operand The decrement operator (--) subtracts one from its operand The statement count++; is functionally equivalent to count = count + 1; The increment operator adds 1 to any integer or floating point value. The two plus signs cannot be separated by white-space. The decrement operator is similar except that it subtracts 1 from the value. The increment and decrement operators are both unary operators because they operate on only one operand.

Assignment Operators num += count; num = num + count; Often we perform an operation on a variable, and then store the result back into that variable Java provides assignment operators to simplify that process For example, the statement num += count; is equivalent to num = num + count; Several assignment operators in Java combine a basic operation with assignment.

Assignment Operators There are many assignment operators, including the following: Operator += -= *= /= %= Example x += y x -= y x *= y x /= y x %= y Equivalent To x = x + y x = x - y x = x * y x = x / y x = x % y

Assignment Operators result /= (total-MIN) % num; The right hand side of an assignment operator can be a complex expression The entire right-hand expression is evaluated first, then the result is combined with the original variable Therefore result /= (total-MIN) % num; is equivalent to result = result / ((total-MIN) % num);

Assignment Operators The behavior of some assignment operators depends on the types of the operands If the operands to the += operator are strings, the assignment operator performs string concatenation The behavior of an assignment operator (+=) is always consistent with the behavior of the "regular" operator (+)