Find the error(s) below:
Assume that the variable counter is declared and initialized to 1. The loop should execute five times, appending the numbers 1–5 to a JTextArea.
```
1 while ( counter < 5 )
2 {
3 numbersJTextArea.append( String.valueOf( counter ) );
4 counter++;
5 }
```
The loop only iterates four times because the loop-condition uses the incorrect rela- tional operator. The condition should use <=. The correct code is:
```
1 while ( counter <= 5 )
2 {
3 numbersJTextArea.append( String.valueOf( counter ) );
4 counter++;
5 }
```
You might also like to view...
Which of the following would be a base case for a summation algorithm (the sum of the numbers from 0 to n)?
a. If n = 0 then summation(n) = 0 b. if n > 0 then summation(n) = 5 c. If n > 0 then summation(n) = getValue(n) d. If n > 0 then summation(n) = n + summation(n-1) e. None of these
A(n) ____ is where you create your projects.
A. workspace B. work window C. workplace D. open work area
Which of the following is a definite indicator of an actual incident, according to Donald Pipkin?
A. unusual system crashes B. reported attack C. presence of new accounts D. use of dormant accounts
When a number gets assigned to a variable that already has a value __________.
(a) the new number overwrites the previous value at that memory location (b) the new number gets assigned to a neighboring memory location (c) the computer issues an error (d) the new value is destroyed and the old value remains