About Question enthuware.jwpv6.2.620 :

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
ETS User

About Question enthuware.jwpv6.2.620 :

Post by ETS User »

Code: Select all

String[] numbers = new int[]{ "1", "2", "3", "4"}
String index = "2";
What would the following EL expression print?

Code: Select all

${numbers[numbers[index-1]]}
The correct answer specified by ETSViewer: 3

How can it be "3", if this code will not compile? :)
1) int[] cannot be cast to String[]
2) no semi-colon after int[] array init;



P.S.: please, upgrade confirmation code generator! i have failed to correctly read it dosen times! :)

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

Re: About Question enthuware.jwpv6.2.620 :

Post by admin »

You are right new int should be replaced with new String. This has now been fixed.

thanks for your feedback!

BTW, if you signup on the forum, you will not be required to enter the code.

HTH,
Paul.

sebastien
Posts: 12
Joined: Tue Mar 26, 2013 2:38 pm
Contact:

Re: About Question enthuware.jwpv6.2.620 :

Post by sebastien »

Hello,

just one point, we need a semicolon after : String[] numbers = new String[]{ "1", "2", "3", "4"} no?

or it will not compile

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

Re: About Question enthuware.jwpv6.2.620 :

Post by admin »

Yes, semicolon should be there. It will still not compile though because it is not the complete contents of the file :)
-Paul.

thituba20
Posts: 3
Joined: Mon Feb 24, 2014 4:47 pm
Contact:

Re: About Question enthuware.jwpv6.2.620 :

Post by thituba20 »

Hello Guys,

This question speaks that answer is 3, but I made a test and the results was 4.
Have anybody tested this question in compilation?
Please, Could anybody make the test too?

Code: Select all

String[] numbers = new String[]{ "1", "2", "3", "4"}; String index = "2";  What would the following EL expression print? ${numbers[numbers[index-1]]}
Best Regards,
Thiago

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

Re: About Question enthuware.jwpv6.2.620 :

Post by admin »

It prints 3.

johnlamb
Posts: 3
Joined: Fri Nov 14, 2014 1:42 pm
Contact:

Re: About Question enthuware.jwpv6.2.620 :

Post by johnlamb »

Hi,
The explanation says:
${numbers[numbers[index-1]]} resolves to ${numbers[numbers[1]]}, which resolves to ${numbers[2]}, which is 3.

Should it say:
${numbers[numbers[index-1]]} resolves to ${numbers[numbers[1]]}, which resolves to ${numbers["2"]}, which is 3.
as numbers[1] is the string 2?

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

Re: About Question enthuware.jwpv6.2.620 :

Post by admin »

You are right. It should be "2". Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests