SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)


 Rhoda Green
 1 years ago
 Views:
Transcription
1 SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz)
2 OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called: unary (1), binary (2) and ternary (3) operators Operators always take specific types of input operands and produce a specific type of output data type. E.g. the multiplication operator in the expression 5 * 2 takes two int literals and produces an int result. Unless the operators have diverging priorities (e.g. * before +), evaluation is performed from left to right: c = 5 * a + 7 * (3  b); Types of operators: arithmetic, comparative, assignment, logical Software Development 1 // 2018W // 2
3 ARITHMETIC OPERATORS (+, , *, /, %) Operations: addition (+), subtraction (), multiplication (*), division (/) and modulodivision (%) Arithmetic operators are binary infix operators: require 2 operands binary positioned between 2 operands infix Modulodivision means division remainder: e.g. 11 / 3 = 3, remainder 2, then 11 % 3 produces 2 Arithmetic operators can be applied to variables and expressions of the types char, byte, int, long, float and double. The 2 operands do not need to be of the same type. Divisions by zero are allowed for the numeric floatingpoint types float and double, in which case the result is the special value infinity. For any integer data type a division by zero will raise a runtime error. Software Development 1 // 2018W // 3
4 POSTFIX AND PREFIX INCREMENT AND DECREMENT Contrary to the other arithmetic operators, increment and decrement operators are unary, meaning, they only have a single operand. ++ is the increment and  the decrement operator They require a variable as operand (literals or expressions are not allowed) and increase, respectively decrease, the variable by 1 Depending on the position of the operator, different values are returned: Prefix (e.g. ++a) first increases/decreases the variable value, then returns the new value Postfix (e.g. a++) increases/decreases the variable value, but returns the value from before the operation Since these operators change variable values as a side effect, try to avoid complex expressions with them, e.g. x = a * b b; (nightmare!) Software Development 1 // 2018W // 4
5 POSTFIX AND PREFIX INCREMENT AND DECREMENT Preincrement int a = 5; int b = ++a; is identical to a = a + 1; b = a; Result: a = 6 b = 6 Postincrement int a = 5; int b = a++; is identical to b = a; a = a + 1; Result: a = 6 b = 5 Software Development 1 // 2018W // 5
6 ARITHMETIC OPERATORS :: EXAMPLE int temperature = 20, delta = 5; // decrease temperature by 10, then multiply with delta. // aside from assigning the result to temperature, delta // is increased by one temperature = (temperature  10) * delta++; // result: temperature is 50, delta is 6 // postfix and prefix decrement: int gamma = delta  delta; // first evaluate delta: result is 5 and delta = 5 // then evaluate delta: result is 5 and delta = 4 // lastly evaluate delta  delta, meaning: 55 // result: gamma is 0, delta is 4 gamma = delta delta; // result: gamma is 2, delta is 6 // modulodivision: get remainder of delta / 6 delta = delta % 6; // result: delta is 0 SWE1.02 / ExpArithmetic.java Software Development 1 // 2018W // 6
7 ARITHMETIC OPERATORS :: OVERVIEW Operator Name Meaning + Positive Sign +a is identical to a  Negative Sign a reverses the sign + Sum a + b computes the sum of a and b  Difference a b computes the difference of a and b * Product a * b computes the product of a and b / Division a / b computes the quotient of a and b % Remainder a % b computes the remainder of a / b ++ Preincrement ++a returns a+1 and increases a by 1 ++ Postincrement a++ returns a and increases a by 1  Predecrement a returns a 1 and decreases a by 1  Postdecrement a returns a and decreases a by 1 In most languages the modulo operator (%) can only be applied to integer numbers, in Java floating point numbers also valid. Software Development 1 // 2018W // 7
8 EQUALITY AND RELATIONAL OPERATORS Equality and relational operators compare two expressions: binary infix operators resulting data type is always boolean Operations: Equal to (==), Not equal to (!=) Greater than (>), Less than (<) Greater than or equal to (>=), Less than or equal to (<=) Example: int a = 3, b = 4, c = 7; boolean check1 = a + b == c; // check1 is true boolean check2 = a > b; // check2 is false SWE1.02 / ExpCompare.java Software Development 1 // 2018W // 8
9 ARITHMETIC OPERATORS :: OVERVIEW Operator Name Meaning == Equal to a == b returns true if a is equal to b!= Not equal to a!= b returns true if a is not equal to b > Greater than a > b returns true if a is greater than b < Less than a < b returns true if a is less than b >= Greater than or equal to a >= b returns true if a is greater than b or equal to b <= Less than or equal to a <= b returns true if a is less than b or equal to b Do not confuse == (equal to) with = (assignment)! These operators are only suited for primitive data types, e.g. do not use it for strings or arrays! Software Development 1 // 2018W // 9
10 ASSIGNMENT OPERATORS Assignment operators assign a value to a variable. = is the simple assignment operators There are many assignment operators with side effects: +=, =, *=, /=, %=, ^=, &=, =, <<=, >>= and >>>= a += b is identical to a = a + b; a = b is identical to a = a  b; a *= b is identical to a = a * b; Example: int a = 3, b = 4, c = 5, d; c += d = a + b; // d is 7 // c is 12 Software Development 1 // 2018W // 10
11 ASSIGNMENT OPERATORS :: OVERVIEW Operator Name Meaning = Simple assignment a = b assigns the value of b to a += Assignment with addition a += b assigns the result of a + b to a = Assignment with subtraction a = b assigns the result of a  b to a *= Assignment with multiplication a *= b assigns the result of a * b to a /= Assignment with division a /= b assigns the result of a / b to a %= Assignment with modulo a %= b assigns the result of a % b to a &= Assignment with AND a &= b assigns the result of a & b to a = Assignment with OR a = b assigns the result of a b to a ^= Assignment with XOR a ^= b assigns the result of a ^ b to a Assignment operators always return the assigned value, which means they can be used in further expressions or cascaded, e.g. int a = b += 5; Software Development 1 // 2018W // 11
12 LOGICAL OPERATORS Logical operators evaluate boolean values: mostly binary infix operators, only! is unary operands and the resulting data type are boolean Operations: AND: && (with ShortCircuitEvaluation), & (no SCE) OR: (with ShortCircuitEvaluation), (no SCE) NOT:! (unary) XOR: ^ ShortCircuitEvaluation (SCE): a && b: If a already evaluates to false, there is no need to evaluate b, since a AND b is definitely false. But if b has side effects, e.g. a && ++x > 1, it may be important to evaluate it anyway. a && b will skip evaluation of b if a is false a & b will always evaluate both a and b Software Development 1 // 2018W // 12
13 LOGICAL OPERATORS :: EXAMPLE // 2 new date values (year, month, day) int y1 = 2007, m1 = 6, d1 = 10; int y2 = 2007, m2 = 7, d2 = 13; // check if first date is earlier than second date boolean earlier = (y1 < y2) (y1 == y2 && m1 < m2) (y1 == y2 && m1 == m2 && d1 < d2); && false true false false false true false true false true false false true true true true // ShortCircuitEvaluation: last line of this expression // will not be evaluated in this example SWE1.02 / ExpLogical.java Software Development 1 // 2018W // 13
14 LOGICAL OPERATORS :: OVERVIEW Operator Name Meaning! Logical NOT && & AND with SCE AND without SCE OR with SCE OR without SCE ^ XOR (no need for SCE)!a evaluates to false if a is true, and to true if a is false a && b evaluates to true if both a and b are true. If a is false, b is not evaluated a & b evaluates to true if both a and b are true. Always evaluates both a and b a b evaluates to true if either a or b are true. If a is true, b is not evaluated. a b evaluates to true if either a or b are true. Always evaluates both a and b a ^ b evaluates to true if a and b are not equal. Always needs to evaluate both a and b Software Development 1 // 2018W // 14
15 BITWISE OPERATORS Bitwise operators combine integer numbers on a bit level: mostly binary infix operators, only ~ is unary accept all integer primitive data types as operands & ^ 0 1 ~ Operations: AND: & OR: XOR: ^ NOT: ~ (unary) Example: byte a = 3, b = 9; System.out.println(a & b); System.out.println(a b); System.out.println(a ^ b); decimal decimal 9 ======== AND: decimal 1 OR: decimal 11 XOR: decimal 10 SWE1.02 / ExpBitOp.java Software Development 1 // 2018W // 15
16 BIT SHIFT OPERATORS Bit shift operators move the bit representation of integer numbers to the left or right, inserting 0 on one side and discarding the bit at the other side. binary infix operators operands can be any integer data type Operations: Signed left shift: a << n Moves all bits in a by n to the left, inserting 0 on the right. Signed right shift: a >> n Moves all bits in a by n to the right, inserting the sign bit on the left. Unsigned right shift: a >>> n Moves all bits in a by n to the right, inserting 0 on the left. Optimization: a << n is equivalent to a multiplication with 2 n a >> n is equivalent to a division by 2 n Shift operations are faster than arithmetic operations. Compilers usually use this fact in their optimization process. Software Development 1 // 2018W // 16
17 BIT SHIFT OPERATORS: EXAMPLE public final class Integer extends Number implements Comparable<Integer> { final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; Characters for IntegerString conversion Public conversion methods public static String tohexstring(int i) { return tounsignedstring(i, 4); } public static String tooctalstring(int i) { return tounsignedstring(i, 3); } public static String tobinarystring(int i) { return tounsignedstring(i, 1); } private static String tounsignedstring(int i, int shift) { char[] buf = new char[32]; int charpos = 32; int radix = 1 << shift; int mask = radix  1; do { buf[charpos] = digits[i & mask]; i >>>= shift; } while (i!= 0); Actual implementation: mask the first 14 bits convert to text shift by same number of bits to the right repeat } } return new String(buf, charpos, (32  charpos)); java.lang.integer Software Development 1 // 2018W // 17
18 STRINGCONCATENATION The + operator can be used to concatenate Strings. If one of the operands is not of type String, it will be converted to a String. Example: int age = 27; System.out.println("Age: " + age + " years"); Convert int age to String. Concatenate 3 Strings. Concatenate 3 Strings. Output: Age: 27 years Software Development 1 // 2018W // 18
19 CONDITIONAL EXPRESSIONS Conditional expressions allow to include alternatives in expressions: condition? alternative1 : alternative2 The condition needs to be of type boolean The alternatives need to be of the same type, or the compiler must be able to convert them to the same type (e.g. Strings and primitive types) If the condition is true, alternative1 is evaluated, otherwise alternative2. Every conditional expression can also be formulated as a branching statement (ifelse; more on that later in Control Structures ). Conditional expressions are more compact and can be an elegant alternative to ifelse, but: Avoid complex conditional expressions, they have a very negative impact on readability of code Software Development 1 // 2018W // 19
20 CONDITIONAL EXPRESSIONS :: EXAMPLE int totalamount = 200, count = 0; // Avoid division by zero int singleamount = count == 0? 0 : totalamount / count; // Do exactly the same with branching if (count == 0) singleamount = 0; else singleamount = totalamount / count; Identical effect as the conditional expression above. // Output "" if count is zero System.out.println("Single amount: " + (count == 0? "" : singleamount)); SWE1.02 / ExpConditional.java Software Development 1 // 2018W // 20
21 OPERATOR PRECEDENCE Usually operators are evaluated from left to right, with a few exceptions: Assignment operators are evaluated from right to left Evaluation strictly follows operator precedence, similar to mathematical expressions, e.g. in * the multiplication has precedence and therefore the result is 15. Parentheses are used to explicitly group operations and change the default behavior, e.g. in (5 + 3) * (3 + 1) the additions have precedence, the result is 24. Software Development 1 // 2018W // 21
22 OPERATOR PRECEDENCE :: EXAMPLES int line = 1; // On even line numbers, output a single separator line, // on odd line numbers, a double separator line. // Additionally increase the line number by 1. System.out.println((line++ 1) == 0? "" : "==="); // Output: === // Value of line: 2 Parentheses required: == has precedence before // + has precedence before << // +, << have precedence before > System.out.println("Greater than 10?: " + (3 + 3 << 1 > 10) ); // Output: Greater than 10?: true int a = 2, b; // Assignments are evaluated from right to left: // first b = 8, then a += b a += b = 8; // Invalid: (a += b) = 8; // It is not allowed to use expressions (includes parentheses) // on the left side of an assignment! SWE1.02 / OpPriority.java Software Development 1 // 2018W // 22
23 Typecasts
24 TYPE CASTS Assigning variables or expressions with a smaller numeric data type to a variable with a larger data type can be done without any explicit instructions. The data type is automatically (implicitly) and without any loss of data or precision converted. In case a variable or expressions with larger numeric data type needs to be assigned to a variable with smaller numeric data, the necessary conversion needs to be stated explicitly, since this might involve loss of data or precision. Example: int birthdate = 1982; int today = 2012; // valid assignment: int to long long agel = today  birthdate; // assignment int to byte: requires type cast! byte ageb = (byte)(today  birthdate); // Compiler error without type cast: // TempRun.java:12: possible loss of precision // found : int // required: byte // byte ageb = today  birthdate; Software Development 1 // 2018W // 24
25 IMPLICIT TYPE CASTS Implicit type casts are possible from smaller to larger data types: byte short int long float double char Implicit cast from long to float potentially involves a loss of precision. A cast from char to short would not involve a loss of precision (both are 16 bit integers), but is still not allowed. Software Development 1 // 2018W // 25
26 EXPLICIT TYPE CASTS Example: Ariane 5 Flight 501 (June 4, 1996) Working code for the Ariane 4 rocket is reused in the Ariane 5, but Ariane 5 was faster (Ariane 5's faster engines trigger a bug in an arithmetic routine inside the rocket's flight computer) The error is in the code that converts a 64bit floatingpoint number to a 16bit signed integer (max. 2^15=32,768). The faster engines cause the 64bit numbers to be larger in the Ariane 5 than in the Ariane 4, triggering an overflow condition that results in the flight computer crashing 36.7sec. after take off Backup computer crashes (same software!), followed 0.05 seconds later by a crash of the primary computer. As a result of these crashed computers, the rocket's primary processor overpowers the rocket's engines and causes the rocket to disintegrate 40 seconds after launch.
27 EXPLICIT TYPE CASTS Explicit type casts are performed by preceding the variable or expression x with the new data type in parentheses: (type)x Type casts often involve data loss Data loss does not generate any kind of warning or error Example: type cast from short to byte, in this case without data loss (16 bits, value is 49) ( 8 bits, value is 49) (16 bits, value is 15) ( 8 bits, value is 15) Software Development 1 // 2018W // 27
28 EXPLICIT TYPE CASTS Example: type cast from short to byte, in this case with data loss (16 bits, value is 514) ( 8 bits, value is 2) Example: short a = 255; byte b = (byte)a; System.out.println(b); float f = 1.9; int i = (int)f; System.out.println(i); Output: 1 1 // type cast short > byte // type cast float > int Cast from floating point to integer number: cuts off fractional part, no rounding! Software Development 1 // 2018W // 28
29 Reference
30 OVERVIEW :: RESULTING DATA TYPES OF ARITHMETIC OPERATIONS +  * / % char byte short int long float double char int int int int long float double byte int int int int long float double short int int int int long float double int int int int int long float double long long long long long long float double float float float float float float float double double double double double double double double double Software Development 1 // 2018W // 30
31 OVERVIEW :: OPERATOR PRECEDENCE Category Operators 0 assignment = += = *= /= %= ^= &= = <<= >>= >>>= 1 conditional operators? : 2 logical OR 3 logical AND && 4 bitwise OR 5 bitwise XOR ^ 6 bitwise AND & 7 equality operators ==!= 8 relational operators < < <= >= instanceof 9 bit shift operators << >> >>> 10 additive operators multiplicative operators * / % 12 instantiation or type cast new (type)x 13 unary operators ++x x +x x! ~ 14 postfix operators x++ x []. Software Development 1 // 2018W // 31
32 SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz)
Information Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationJAVA 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 informationChapter 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 informationBasic 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 informationJava 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 informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationInformation Science 1
Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixedtype
More informationProf. 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 informationChapter 3 Structured Program Development in C Part II
Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 3.7 The while Iteration Statement An iteration statement (also called
More informationOperators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special builtin symbols that have functionality, and work on operands operand an input to an operator Arity  how many operands an operator
More informationLECTURE 3 C++ Basics Part 2
LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special builtin symbols that have functionality, and work on operands. Operators are actually functions that use
More informationThe 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 informationThe 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 informationOperators. 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 informationGO  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 informationSECTION II: LANGUAGE BASICS
Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators
More information3. Java  Language Constructs I
Educational Objectives 3. Java  Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks
More informationDeclaration and Memory
Declaration and Memory With the declaration int width; the compiler will set aside a 4byte (32bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationFundamentals of Programming Session 7
Fundamentals of Programming Session 7 Instructor: Reza EntezariMaleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationModule 2  Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1
Module 2  Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions
More information1.3b Type Conversion
1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type
More informationIntroduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands
Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationObjects 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 informationA 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 informationInformatics Ingeniería en Electrónica y Automática Industrial
Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical
More informationA flow chart is a graphical or symbolic representation of a process.
Q1. Define Algorithm with example? Answer: A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of
More informationLecture 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 informationFundamentals of Programming
Fundamentals of Programming Lecture 3  Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110001 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 informationECE 122 Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions
More informationComputers Programming Course 6. Iulian Năstac
Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap
More informationCT 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 informationIn Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.
Formulating Algorithms with TopDown, Stepwise Refinement Case Study 2: SentinelControlled Repetition In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability.
More informationChapter 2: Using Data
Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time
More informationUNIT 3 Introduction to C++
UNIT 3 Introduction to C++ C++ Character Sets: Letters AZ, az Digits 09 Special Symbols Space +  * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 21 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationExpressions and Precedence. Last updated 12/10/18
Expressions and Precedence Last updated 12/10/18 Expression: Sequence of Operators and Operands that reduce to a single value Simple and Complex Expressions Subject to Precedence and Associativity Six
More informationProgramming in C++ 5. Integral data types
Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long
More informationWill introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators
Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships
More informationOperators 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 informationMore 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 informationChapter 12 Variables and Operators
Chapter 12 Variables and Operators Basic C Elements Variables Named, typed data items Operators Predefined actions performed on data items Combined with variables to form expressions, statements Statements
More informationJAC444  Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course
JAC444  Lecture 1 Introduction to Java Programming Language Segment 4 1 Overview of the Java Language In this segment you will be learning about: Numeric Operators in Java Type Conversion If, For, While,
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements  A statement is some action or sequence of actions, given as a command in code. A statement
More informationOperators 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 informationExpressions & Assignment Statements
Expressions & Assignment Statements 1 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions ShortCircuit Evaluation Assignment Statements
More informationOperators 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 informationChapter 12 Variables and Operators
Chapter 12 Variables and Operators Highlights (1) r. height width operator area = 3.14 * r *r + width * height literal/constant variable expression (assignment) statement 122 Highlights (2) r. height
More informationLe 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 informationChapter 7. Expressions and Assignment Statements ISBN
Chapter 7 Expressions and Assignment Statements ISBN 0321330250 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions ShortCircuit
More informationA complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
More informationbitwise 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 informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
More informationJava 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 informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationSir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )
Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES: VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.
More informationChapter 4. Operations on Data
Chapter 4 Operations on Data 1 OBJECTIVES After reading this chapter, the reader should be able to: List the three categories of operations performed on data. Perform unary and binary logic operations
More informationJava 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 informationChapter 2 Elementary Programming
Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical
More information2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C
University of Illinois at UrbanaChampaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used
More informationChapter 3 Structure of a C Program
Chapter 3 Structure of a C Program Objectives To be able to list and describe the six expression categories To understand the rules of precedence and associativity in evaluating expressions To understand
More informationChapter 2: Using Data
Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are 2 31 through 2 311. These are the highest and lowest values that
More informationOperators & 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 information3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.
3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:
More informationExpressions. 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 informationCSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI
CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 31 / 2014 Instructor: Michael Eckmann Today s Topics Comments and/or Questions? Pseudocode Programming exercise to determine projected homeruns How Java determines
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationExercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014
Exercises Software Development I 05 Conversions and Promotions; Lifetime, Scope, Shadowing November 5th, 2014 Software Development I Winter term 2014/2015 Priv.Doz. Dipl.Ing. Dr. Andreas Riener Institute
More informationCOMP6700/2140 Operators, Expressions, Statements
COMP6700/2140 Operators, Expressions, Statements Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU 3 March 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Operators,
More informationChapter 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 ShortCircuit Evaluation Assignment
More informationSlide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto
CS 170 Java Programming 1 Expressions Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 What is an expression? Expression Vocabulary Any combination of operators and operands which, when
More informationChapter 7. Expressions and Assignment Statements (updated edition 11) ISBN
Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0321493621 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean
More informationOutline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands
Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how
More informationBits, Words, and Integers
Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are
More informationData and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence
Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public
More informationTypes and Expressions. Chapter 3
Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's
More informationZhengLiang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / ZhengLiang Lu Java Programming 45 / 79 Example Given a radius
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationReview: 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 informationAnnouncements. Lab Friday, 12:30 and 34:30 in Boot your laptop and start Forte, if you brought your laptop
Announcements Lab Friday, 12:30 and 34:30 in 26152 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 informationChapter 2. Elementary Programming
Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,
More informationTools : The Java Compiler. The Java Interpreter. The Java Debugger
Tools : The Java Compiler javac [ options ] filename.java... depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. O: Optimizes code,
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationPrefix/Infix/Postfix Notation
Prefix/Infix/Postfix Notation One commonly writes arithmetic expressions, such as 3 + 4 * (52) in infix notation which means that the operator is placed in between the two operands. In this example, the
More informationCHAPTER 3 Expressions, Functions, Output
CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers  Number
More informationEng. Mohammed S. Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationExpressions 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 informationISA 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 informationBut first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15
Integer Representation Representation of integers: unsigned and signed Sign extension Arithmetic and shifting Casting But first, encode deck of cards. cards in suits How do we encode suits, face cards?
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 21 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More information3. Java  Language Constructs I
Names and Identifiers A program (that is, a class) needs a name public class SudokuSolver {... 3. Java  Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations,
More information