Chap3 - Chapter 3 Numerical Data Topics Variables Numeric...

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

View Full Document Right Arrow Icon
Chapter 3 Numerical Data
Background image of page 1

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

View Full DocumentRight Arrow Icon
Topics Variables Numeric data types Assignment Expressions
Background image of page 2
Numeric Data and Operations So far, our programs have used only String data It is common to use computers for numeric calculations We can write literal numbers into our programs - just write the number We need a way to store numeric data - variables
Background image of page 3

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

View Full DocumentRight Arrow Icon
Variables In mathematical expressions, we often use x and y to represent unknown values and to make a placeholder for many different values y = x 2 + 5 A variable is used in a similar way in a program A variables has a Java identifier for a name.
Background image of page 4
Variables In the last chapter, we declared variables whose location stored the address of an object Now we need to learn to declare variables to store numeric data. A declaration sets aside memory locations to store data values. These memory locations are called variables , and x and y are the names we associate with the memory locations. As before, we need to say what kind of data the variable represents.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Variables A variable has three properties: A memory location to store the value. The type of data stored in the memory location. The name used to refer to the memory location.
Background image of page 6
Variable Declarations The syntax for declaring variables is <data type> <variables>; where <variables> is a sequence of identifiers separated by commas. Every variable we use in a program must be declared.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Numeric Types There are six numeric data types in Java: We nee to be able to use two basic kinds of numbers. We have several types for each kind of number to allow for different ranges
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

Chap3 - Chapter 3 Numerical Data Topics Variables Numeric...

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

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