Counting Higher

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Put a copy of statements 2 and 3 right after the first copy.

Counting Higher

The following fragment:

int count = 0;                  // statement 1

System.out.println( count ) ;   // statement 2
count = count + 1;              // statement 3

System.out.println( count ) ;   // statement 4

count = count + 1;               
System.out.println( count ) ;    

will print out

0
1
2

The statement count = count + 1 increments the number in count. Sometimes programmers call this "incrementing a variable" although (of course) it is really the number in the variable that is incremented.

QUESTION 18:

What does the following assignment statement statement do:

sum = 2*sum ;

(What are the two steps, in order?)