About Question enthuware.ocajp.i.v7.2.914 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
Enya-8171
Posts: 1
Joined: Thu Sep 04, 2014 2:46 pm
Contact:

About Question enthuware.ocajp.i.v7.2.914 :

Post by Enya-8171 »

Consider the following code:

public static void main(String[] args) {
int[] values = { 10, 30, 50 };
for( int val : values ){
int x = 0;
while(x<values.length){
System.out.println(x+" "+val);
x++;
}
}
}

The output of the method is:

0 10
1 10
2 10
0 30
1 30
2 30
0 50
1 50
2 50

The question is: How many times is 2 printed out?

What is the correct answer?

admin
Site Admin
Posts: 9112
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.914 :

Post by admin »

Option 4 - 3 times. That is what the output shows as well.
If you like our products and services, please help us by posting your review here.

PhoenixtheII
Posts: 1
Joined: Thu Apr 23, 2015 4:34 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.914 :

Post by PhoenixtheII »

Option 1, 0

the println is each time concatted with 'val', thus there will never be just '2' printed.

admin
Site Admin
Posts: 9112
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.914 :

Post by admin »

The question doesn't ask how many times just 2 is printed.
If you like our products and services, please help us by posting your review here.

sbeexoo
Posts: 1
Joined: Thu Sep 03, 2015 8:31 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.914 :

Post by sbeexoo »

Hello,
I answered 0 because it was NOT ONLY 2 but also something else. It should be more precise.

Maybe it is clear for you but for me (I am a boolean) it's clearly not. I asked myself during this question what should I answer ? (Sometimes you ask some tricky questions and we are wrong because of subtilities so... you should be coherant)

Just an opinion and it don't change the fact I really thank you for that work !

DazedTurtle
Posts: 26
Joined: Wed Oct 02, 2019 1:42 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.914 :

Post by DazedTurtle »

This question is essentially identical to enthuware.ocpjp.i.v11.2.3222, isn't it? Why does the test have both?

admin
Site Admin
Posts: 9112
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.914 :

Post by admin »

Right. There is no need to have both. Removed one.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests