Question: 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?
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 sum = 0;
intproduct = 1;
int max = 20;
for (int i = 1; i <= max; i++)
sum = sum + i;
product = product * i;
System.out.println("The sum is " + sum +
" and the product is " + product);
Step by Step Solution
3.54 Rating (168 Votes )
There are 3 Steps involved in it
The sum is 210 and the product is 210It is lik... View full answer
Get step-by-step solutions from verified subject matter experts
