Information
package quiz;
public class Quiz24 {
private static int increment(int i){
int num= (++i) + (i++);
return num;
}
public static void main(String[] args) {
for(int i=0; i < 5; 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 Quiz24 {
private static int increment(int i){
int num= (++i) + (i++);
return num;
}
public static void main(String[] args) {
for(int i=0; i < 5; increment(i)){
System.out.print(i);
}
}
}
Select correct answer from options below :
Correct In a for loop, we can use method call as the iteration expression.
But, here the code fails to capture the result of the method call. it should be i = increment(i)
Therefore, value of i does not change and its an infinite loop.
Incorrect In a for loop, we can use method call as the iteration expression.
But, here the code fails to capture the result of the method call. it should be i = increment(i)
Therefore, value of i does not change and its an infinite loop.