Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock exam question doubt from javacertifications.net ?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
following is the question ;

Questions no -20

What get printed when the following JSTL code fragment is executed?

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="item" value="2"/>
<c:forEach var="item" begin="0" end="0" step="2">
<cut value="${item}" default="abc"/>
</c:forEach>



options
A)0
B)2
C)abc
D)4

the correct answer is OPTION A i.e. 0. i thought the answer should be 2. i ran it but it is coming out to be 0. checked syntax for forEach tag and didnt find a thing. please help ?
 
Vijay Vishwa
Ranch Hand
Posts: 40
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let put it through similar simple java loop



This is what happening is the JSTL code also

item varable is declared and set to 2

Next in the for loop, the counter varaible is item and loop starts and ends with 0
So in the first iteration 0 is assigned to the item and that is what printed.



 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have initialized your item variable again for looping, so has nothing to do with your previous assignment.
 
Atul Shrivastava
Greenhorn
Posts: 19
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you started with 0 and the loop ended on 0 itself, resulting in the output 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic