frandariusscott
frandariusscott
15.11.2021 • 
Mathematics

The following for loop prints the numbers 1 to 20 on one line with a space between. for (int i = 1; i <= 20; i++)
{
System.out.print(i + " " ); // prints each value of i followed by a space on one line
}

Question

Consider the for loop example above. Assume you want to adjust the loop to print only the even values from 1 and 20. What must the loop elements - counter initialization, conditional statement, and counter modification - be set to in order to accomplish the goal.

Review all options listed below carefully. You MUST select 3 answers; one for each element/category:

Counter initialization
Conditional statement
Counter modification
a. int i = 0;
b. int i = 1;
c. int i = 2;
d. i < 20;
e. i <= 20;
f. i > 20;
g. i++;
h. i+=1-;
i. i+=2;

Solved
Show answers

Ask an AI advisor a question