Lecture 3: I/O Investigation of Rational Numbers



Variables

Definition:

Value variable: A storage to hold only one value of the same type.

Type: a set of all values of the same characteristics.

Example 1: The variable Box holds one ball at a time from its type Balls

Example 2: The variable personAge holds one value 16, a member of the set Teens.

Assignment Symbol:

(

1. It is used to move a value on the right side into a variable on the left side of the symbol; The value must be a member of the variable type.

A ( 5;

2. It is used to move a value in a variable on the right side into a variable on the left side, for example A (B;

3. It is used to move the result of expression on the right side into a variable on the left side, for example A (B*2 +3;

How to declare a variable:

Reference variable: A storage to hold a reference (address) which leads to another storage which holds a value.

Example:

public class Rational

{

// Object Frame

int numerator;

int denominator;

// constructors

public Rational()

{ numerator = 0;

denominator = 1;}

public Rational(int num, int denom)

{numerator = num;

denominator = denom; }

// instance methods

public void printFraction()

{ System.out.println(numerator + "/" + denominator);}

}

-----------------------

14

Teens = {13,14,15,16,17,18,19}

personAge

Box

Balls = {Green, Orange, Purple}

13

15

17

18

16

19

16

13

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download