Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

mock exam question doubt from javacertifications.net ?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • 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">
<c:out 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 ?
 
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.



 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • 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.
 
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.
 
Destroy anything that stands in your way. Except this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic