• recategorized by
5,069 views
3 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

2 Answers

Best answer
7 7 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 1 vote

Answer will be B)

Here the value printed

when ((k%3)==1)

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

Answer:
Position:
Show:

Related questions

6 6 votes
1 answers 1 answer
9.3k
9.3k views
go_editor asked Jun 13, 2016
9,342 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 2 votes
3 answers 3 answers
6.0k
6.0k views
go_editor asked Jun 13, 2016
6,025 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...
8 8 votes
4 answers 4 answers
5.0k
5.0k views
go_editor asked Jun 13, 2016
4,988 views
Repeated execution of simple computation may cause compounding ofround-off errorssyntax errorsrun-time errorslogic errors
8 8 votes
1 answers 1 answer
5.1k
5.1k views
go_editor asked Jun 13, 2016
5,053 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$