Tracing

Tracing loops and arrays

Passing arrays as parameters

Objects in java are passed by reference. Primitive data types are passed by value. This means that when you pass an Object as a method parameter, you are not giving the method the Object itself, but a reference to it.

String [] theirActualGrades= {"F", "F", "F", "F", "F", "A", "B", "C", "F", "D"};
myInstance.defaultFillGrade(theirActualGrades);

If I write another line after the call to the method: I get that all grades in the array theirActualGrades are A's

Another small method which accepts an array as a parameter:

Again, somewhere an array was instatiated:
int[] table = new int[24];

And a sample invocation of the method looks like:

total = sum(table);

Some more array traces. How many lines of output would be in the following?:

output
and output
and output
and has no output

More Loop Examples:

Yields:
Looping, round 1
Looping, round 2
Looping, round 3
Looping, round 4

Yields: ?

What do these do?

y *= 2;
x += 1;
x++;
++x;

Write a for loop that generates the following output
(many middle terms are intentionally left out):

-1000
-996
-992
-988
//... output deleted
988
992
996
1000

Answer

an if question:
For what exact range of values of the variable x does the code below print the letter C? these

another loop (with a switch) to trace

code and output

Specific to lab 7:

loops and sequencing (the order of sequencing) are very very very very very very very important to programming

Using the code I provided with editing so will compile:

looks like. Why?

Set x and y coordinate in outer loop:

how this would increment and its applet
and

initialize chosenColor array

Discussion on how this would look and its applet
and

where to change color

Discussion on how this would look and its applet

and

Simple placement of a line, in general, makes a difference


Think about how this above code differs from the following: and its applet

It is a very subtle difference in the placement of the line
localX = initialBoxX + col*width;

Consider what it does to the output...