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...
According to Excel's order of operations, addition and subtraction are done before exponentiation
Indicate whether the statement is true or false
Computer Science & Information Technology
In HTML, which of the following is not an example of attribute minimization?
A. checked B. value C. noresize D. selected
Computer Science & Information Technology