Ask Question
7 May, 08:57

Consider the following two code segments. In both, assume that n is an integer variable that has been declared and initialized. Segment 1 int prod = 1; int i; for (i = 2; i < = n; i++) { prod * = i; } System. out. println (prod); Segment 2 int prod = 1; int i = 2; while (i < = n) { prod * = i; i++; } System. out. println (prod); For which integer values of n do these code segments print the same result?

+4
Answers (1)
  1. 7 May, 10:41
    0
    For every value of n.

    Explanation:

    In code segment 1 it uses for loop to store the product of integers from 2 to n in variable product it does that by using a for loop after that printing the product.

    In the other code segment the same thing is done the only difference is that it uses a while loop instead of for loop to find the product and then printing the product.

    So the result will be same for every value of n.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider the following two code segments. In both, assume that n is an integer variable that has been declared and initialized. Segment 1 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers