We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byJeremiah Barrett
Modified over 2 years ago
© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5; a literal (5) is assigned to x x = y + 2; the value of an expression (y + 2) is assigned to x x = z; the value of another variable ( z ) is assigned to x
© 2007 Lawrenceville Press Slide 2 Variable Assignment A variable can store only one value at any time. int x; x = 5; x = 10; x 5 10
© 2007 Lawrenceville Press Slide 3 Primitive Data Types TypeStorage Required int 4 bytes double 8 bytes char 2 bytes boolean 1 bit
© 2007 Lawrenceville Press Slide 4 Abstract Data Types A variable declared with a class is called an object. For example, the object spot is type Circle: Circle spot = new Circle(4);spot getRadius() area()
© 2007 Lawrenceville Press Slide 5 C# Packages Numerous packages are included with C# Packages contain classes Packages can be added to an application with an Using statement. For example, the statement Using System; makes the Scanner class and its methods accessible to the application.
© 2007 Lawrenceville Press Slide 6 Integer Division Integer division ( / ) is performed when both operands are integers. Only the integer portion of the quotient is returned:
© 2007 Lawrenceville Press Slide 7 Real Division Real division ( / ) is performed when one or both operands are type double. The entire quotient, including the decimal portion is returned: double result; result = 20.0/7.0;//result is 2.857
© 2007 Lawrenceville Press Slide 8 Modulus Division Modulus division ( % ) returns the remainder of a division operation:
© 2007 Lawrenceville Press Slide 9 Operator Precedence Operators in Java have the following precedence: 1. multiplication and division 2. addition and subtraction Operators of the same precedence are evaluated in order from left to right. For example, multiplication is performed first, then division, and finally addition: * 4 / 2 = 17
© 2007 Lawrenceville Press Slide 10 Changing the Order of Operations The order in which operators are evaluated can be changed by using parentheses. For example, addition is performed first, then multiplication, and finally division: (5 + 6) * 4 / 2 = 22
© 2007 Lawrenceville Press Slide 11 Type Casting Type Casting converts a number of one type to a number of a different, but compatible type. Type casting is used to: 1.make the operand types in an expression match. For example, wholeNum = (int)y * 2 2.truncate the decimal portion of a double. For example, wholeNum = (int)z 3.change the way in which a division ( / ) operation will be performed. For example, realDivision = (double)a / (double)b
© 2007 Lawrenceville Press Slide 12 Programming Errors Syntax errors violate the rules of C#. Logic errors, also called semantic errors, occur in statements that are syntactically correct, but produce undesired or unexpected results. Run-time errors, also called exceptions, halt program execution at the statement that cannot be executed. One type of exception is called DividByZeroExecption.
1 CSci 1130 Intro to Programming in Java Variables and Calculations.
First Program in JAVA: Printing a Line of Text Modifying our First Java Program Escape Sequences Displaying Text with printf Data types in JAVA.
Copyright 2008 by Pearson Education Review pages for the AP CS Exam NOTE: Sections that are not considered part of the Java Subset for the AP CS exam are.
1 CM Programming with Java Chapter 1 Getting Started.
Arithmetic Calculations n Basic arithmetic operators: + addition - subtraction * multiplication / division %remainder (or modulus). Same precedence and.
Copyright © 2003 Pearson Education, Inc. Slide 1.
COMP 110: Introduction to Programming Tyler Johnson January 26, 2009 MWF 11:00AM-12:15PM Sitterson 014.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
1001ICT Programming 1 Semester 1, 2011 Lecture 8 Course Review 1.
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Lecture 5 Types, Expressions and Simple I/O COMP1681 / SE15 Introduction to Programming.
Copyright © 2002 Pearson Education, Inc. Slide 1.
LECTURE 3: BASIC C OPERATORS. Objectives In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment.
OBJECTIVES 2.5 Division of Integers and Order of Operations Slide 1Copyright 2012, 2008, 2004, 2000 Pearson Education, Inc. aDivide integers. bUse the.
Chapter 5 Implementing a simple class. This chapter discusses n Implementing class definitions. n How to store data in an object and how to write method.
Arrays Declaring and Creating Arrays Examples using Arrays Enhanced for Statement Passing Array Methods Multi Dimensional Array Topics.
Chapter 1 C++ Basics. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-2 Learning Objectives Introduction to C++ Origins, Object-Oriented.
4 Copyright © 2005, Oracle. All rights reserved. Exploring Primitive Data Types and Operators.
Escape Sequences \nnewline \t tab \bbackspace \rcarriage return \single quote \double quote \\backslash.
Lesson 2B – Operations, Characters, Mixing Data Types, Order of Operations By John B. Owen All rights reserved ©2011.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 3 Numerical Data.
© Vinny Cahill 1 Writing a Program in Java. © Vinny Cahill 2 The Hello World Program l Want to write a program to print a message on the screen.
Literals Why does this produce an error? float x = 2.5;
LESSON 1.4 EVALUATING EXPRESSIONS. Homework Check & REVIEW Class work and Homework 1.Exercise Pages P. 14 – 16 Q #
Type Conversion. C provides two methods of changing the type of an expression: Type conversion (done implicitly) Cast expressions (done explicitly) Examples.
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
Computation u When processing data we subject it to a variety of transformations or computations. u The type of data determines the set of valid operations.
Chapter 3 Fundamental Data Types of Java Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas,
COMP 110: Introduction to Programming Tyler Johnson Mar 2, 2009 MWF 11:00AM-12:15PM Sitterson 014.
© 2016 SlidePlayer.com Inc. All rights reserved.