Computer Science, asked by twinklegupta7563, 1 year ago

Int i;for(int i =5;i<=1;i++){if(i%2==1)continue;System.out.print(i+" ");}

Answers

Answered by coolcatfatrat
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 nain31
52
 \huge \bold{CODING}

Int i ;

for(int i = 5 ;i<=1;i++)

{

if(i%2==1)

continue;

System . out . print(i+" ")

}

 \boxed{int \: i }

For initialization loop with 5 and will work 5 times.

 \boxed{if(i \% 2==1)}

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.

 \boxed{continue}

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.

 \boxed{Sy stem \: . \: out \:. \:print(i+" ") \: ;}

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.

 \huge \bold{DRYRUN}

◼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.

 \huge \bold{OUT\: PUT}

Since, the printing condition for 4 and 2 will execute so,

 \huge \boxed{\bold{4\:2}}
Similar questions