Int i;for(int i =5;i<=1;i++){if(i%2==1)continue;System.out.print(i+" ");}
Answers
Answered by
12
I am guessing you are referring to the icse board question (but you have put the wrong sign in the test condition). If you want the answer to the board question, it is:
4 2
But as per your given question, the loop will never execute because if i=5 it is not <=1.
Answered by
52
Int i ;
for(int i = 5 ;i<=1;i++)
{
if(i%2==1)
continue;
System . out . print(i+" ")
}
▶
For initialization loop with 5 and will work 5 times.
▶
For checking whether value of i is an odd number, because % gives remainder .
If number is not divisible by 2 ,gives remainder 1 ,then its odd.
▶
A jump statement , which if the condition will be true , that condition will be skipped and it will move to its next value and will check.
▶
A printing statement that will print the value of i if the condition will be true and continue statement will skip the value of i to its next value.
◼i=5
Since, the condition if(5%2==1) is true so, continue statement will work and will skip printing statement.
◼i=4
Since, the condition if(4%2==1) is false so, continue statement will be skipped and printing statement will execute.
◼i=3
Since, the condition if(3%2==1) is true so, continue statement will work and will skip printing statement.
◼i=2
Since, the condition if(2%2==1) is false so, continue statement will be skipped and printing statement will execute.
◼i=1
Since, the condition if(1%2==1) is true so, continue statement will work and will skip printing statement.
Since, the printing condition for 4 and 2 will execute so,
Similar questions
Science,
7 months ago
Math,
7 months ago
English,
7 months ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago