About Question enthuware.ocajp.i.v7.2.914 :
Moderators: Site Manager, fjwalraven
-
- Posts: 1
- Joined: Thu Sep 04, 2014 2:46 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.914 :
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?
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?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.914 :
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.
-
- Posts: 1
- Joined: Thu Apr 23, 2015 4:34 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.914 :
Option 1, 0
the println is each time concatted with 'val', thus there will never be just '2' printed.
the println is each time concatted with 'val', thus there will never be just '2' printed.
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.914 :
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.
-
- Posts: 1
- Joined: Thu Sep 03, 2015 8:31 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.914 :
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 !
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 !
-
- Posts: 26
- Joined: Wed Oct 02, 2019 1:42 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.914 :
This question is essentially identical to enthuware.ocpjp.i.v11.2.3222, isn't it? Why does the test have both?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.914 :
Right. There is no need to have both. Removed one.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 148 guests