EX 4.12. What is wrong with the following code fragment? What are three distinct ways it could be changed to remove the flaw?

```
count = 50;
while (count >= 0)
{
System.out.println(count);
count = count + 1;
}
```


The loop is infinite because count initially is greater than zero, and continues to increase in value. The flaw can be removed by (1) decrementing rather than incrementing count, (2) initializing count to 0 and using, as the condition of the while loop, count <= 50, and (3) picking an upper limit and using, as the condition of the while loop, count <= upperLimit.

Computer Science & Information Technology

You might also like to view...

What must match in the communications between all NICs on a network?

A. frame B. MAC address C. frame type D. IP address

Computer Science & Information Technology

A(n) ____________________ is information included at the top of every page in your worksheet.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

One downside to using a web development tool is that sometimes they insert unnecessary code, creating larger, slower-loading webpages.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

The _____ area on the status bar displays common calculations, such as SUM or AVERAGE, for selected numbers in the worksheet.

A. AutoFormat B. AutoComplete C. AutoFunction D. AutoCalculate

Computer Science & Information Technology