0 of 1 questions completed
Questions:
Information
package quiz;
public class Quiz25 {
private static int increment(int i){
int num= (++i) + (i++);
return num;
}
public static void main(String[] args) {
for(int i=0; i < 5; i = increment(i)){
System.out.print(i);
}
}
}
You have already completed the quiz before. Hence you can not start it again.
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Question 1 of 1
package quiz;
public class Quiz25 {
private static int increment(int i){
int num= (++i) + (i++);
return num;
}
public static void main(String[] args) {
for(int i=0; i < 5; i = increment(i)){
System.out.print(i);
}
}
}
Select correct answer from options below:
Correct The increment portion in for loop can be a method call as well.. hence the syntax is correct.
Although, the increment is at the top of for loop, it gets executed after the for loop body (in this case, the print statement) is executed.
So, i gets printed before the increment method is called.
Incorrect The increment portion in for loop can be a method call as well.. hence the syntax is correct.
Although, the increment is at the top of for loop, it gets executed after the for loop body (in this case, the print statement) is executed.
So, i gets printed before the increment method is called.