Part 3: a. What are the three required expressions of a for-loop? (1 pts) b. Con
ID: 672411 • Letter: P
Question
Part 3:
a. What are the three required expressions of a for-loop? (1 pts)
b. Consider the following code. This code was written to generate the output as show
Output 2. However, there is an error in this code. Correct the code so that it is ablegenerate the desired output. (2 pts)
int count = 0;
while (count < 10)
{
System.out.println("count:" + count);
}
Output 2
count:0
count:1
count:2
count:3
count:4
count:5
count:6
count:7
count:8
count:9
c. What is the output of the following code? (2 pts)
int i =0;
do
{
System.out.println("i is : " + i);
i++;
}while(i < 5);
Note: The answers to the questions (a through c) above should be typed in the block of
comments in the java file such as;
//a) The three requirements of a loop are …
//b) The corrected code is …
//c) The output of the given code is …
Explanation / Answer
//a. What are the three required expressions of a for-loop ? 1. initialization, 2. Condition, 3. Increment/Decrement
//b) The corrected code is …
// int count = 0;
// while (count < 10)
// {
// System.out.println("count:" + count++);
// }
//c) The output of the given code is …
//i is : 0
//i is : 1
//i is : 2
//i is : 3
//i is : 4