Page 1 of 1
About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Sep 04, 2014 2:51 pm
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?
Re: About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Sep 04, 2014 7:38 pm
by admin
Option 4 - 3 times. That is what the output shows as well.
Re: About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Apr 23, 2015 4:45 am
by PhoenixtheII
Option 1, 0
the println is each time concatted with 'val', thus there will never be just '2' printed.
Re: About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Apr 23, 2015 10:15 am
by admin
The question doesn't ask how many times just 2 is printed.
Re: About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Sep 03, 2015 8:37 am
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 !
Re: About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Nov 07, 2019 6:24 pm
by DazedTurtle
This question is essentially identical to enthuware.ocpjp.i.v11.2.3222, isn't it? Why does the test have both?
Re: About Question enthuware.ocajp.i.v7.2.914 :
Posted: Thu Nov 07, 2019 10:37 pm
by admin
Right. There is no need to have both. Removed one.
thank you for your feedback!