recategorized by
3,660 views
3 votes
3 votes

Consider the following code segment:

for (int k=0; k<20; k=k+2)
{
    if (k % 3 == 1)
        system.out.print(k+ " ");
}

What is printed as a result of executing the code segment?

  1. 4 16
  2. 4 10 16
  3. 0 6 12 18
  4. 1 4 7 10 13 16 19
recategorized by

2 Answers

Best answer
6 votes
6 votes

Option B

4  10  16 

k =0 % 3 =0 since k is incremented by 2

 = 2%3=2 

  =4%3=1 -----------------prints 4

  = 6%3 =0

  = 8%3=2

 =10%3=1 ------------- prints 10

=12%3 =0

 .........

Therefore Output is 4  10  16 

selected by
1 votes
1 votes

Answer will be B)

Here the value printed

when ((k%3)==1)

And 4,10,16 gives those value between 1 to 20

Answer:

Related questions

6 votes
6 votes
1 answer
1
go_editor asked Jun 13, 2016
8,630 views
We can make a class abstract byDeclaring it abstract using the virtual keywordMaking at least one member function as virtual functionMaking at least one member function a...
2 votes
2 votes
2 answers
2
go_editor asked Jun 13, 2016
4,359 views
In C, what is the effect of a negative number in a field width specifier?the values are displayed right justifiedthe values are displayed centeredthe values are displayed...
7 votes
7 votes
4 answers
3
go_editor asked Jun 13, 2016
3,278 views
Repeated execution of simple computation may cause compounding ofround-off errorssyntax errorsrun-time errorslogic errors
8 votes
8 votes
1 answer
4
go_editor asked Jun 13, 2016
4,010 views
Consider the graph shown in the figure below:Which of the following is a valid strong component?$a, c, d$$a, b, d$$b, c, d$$a, b, c$