What does the following fragment of code display? What do you think the programmer intended the code to do, and how would you fix it?

```
int product = 1;
int max = 20;
for (int i = 0; i <= max; i++)
product = product * i;
System.out.println(“The product is “ + product);
```


The product displayed is 0. It is likely that the programmer wanted to compute the product of the first 20 integer values. Change the for loop to be:
```
for (int i = 1; i <= max; i++)
```

Computer Science & Information Technology

You might also like to view...

The TCP/IP Protocol Suite

a. was originally designed for commercial purposes b. was originally designed for use on a network connecting U.S. government agencies c. originally contained only TCP and IP d. was originally a proprietary protocol

Computer Science & Information Technology

Write a program to input the radius of the base and height of a cylinder, and calculate and print the surface area, volume, and area of the base of the cylinder.Which words from the problem statement above could we use to determine the operations for this program?

A. input, calculate, print B. cylinder, program, volume C. height, cylinder, radius D. radius, cylinder, print

Computer Science & Information Technology

To create a multilevel list, click the Multilevel List button in the Paragraph group on the ____________________ tab.

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

Computer Science & Information Technology

A new version of SDRAM, referred to as __________, can send data twice per clock cycle, once on the rising edge of the clock pulse and once on the falling edge.

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

Computer Science & Information Technology