lec02 - Lecture 2 Variables Data types Arithmetic...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 125 Course Notes Lecture 2, Slide 1 • Variables • Data types • Arithmetic operators (Savitch 2.1) Lecture 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 2, Slide 2 Variables Variable – stores a piece of data. • Example: peopleInClass = 60; identifier value
Background image of page 2
CS125 Course Notes Lecture 2, Slide 3 Variables continued • Need to be declared before they can be used. indicate what kind (type) of data they will hold. • Once they are declared, we can asign variables a value . this value must be the same type as the variable.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 2, Slide 4 Declaring a variable Type Variable1, Variable2, …; Examples: int styleNumber, numberofChecks; char answer; double amount, interestRate; From p. 49
Background image of page 4
CS125 Course Notes Lecture 2, Slide 5 Rules for naming variables 1. Must start with a letter 2. Can only contain letters, numbers and underscore 3. Case sensitive: theVariable is not the same as thEVaRiabLE 4. Can’t be a reserved word For full list, refer to Appendix 1 in Savitch text. 5. Convention: start with lowercase letter. Every new word starts with uppercase letter.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 2, Slide 6 Examples Good Names input myVar theBox numPeople Unacceptable Names (Java will view these as an error) 1life sto.p class !!hel#O Acceptable but not good SelfTest BAdNAME X
Background image of page 6
CS125 Course Notes Lecture 2, Slide 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2009 for the course MATH 135 taught by Professor Andrewchilds during the Fall '08 term at Waterloo.

Page1 / 22

lec02 - Lecture 2 Variables Data types Arithmetic...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online