Forums Register Login

JSP doubt?

+Pie Number of slices to send: Send
Guys,

The code below is from David Bridgewater's,


The question is What is output to the web page on the second access to the same instance of the following JSP?
(Choose one.)

How the answer is 3?? I thought 4!
+Pie Number of slices to send: Send
when this jsp is accessed first time, it will run JspInit() thus incrementing x by 1.Then, <%= x++ %> would increment x by 1.
By now x=2.
Now if you access the same instance 2nd time, JspInit() wouldnot be called. just <%= x++ %> would increment x by 1.
So the final value of x will be 3.

Thanks and regards,
Saurabh
+Pie Number of slices to send: Send
 

By now x=2.
Now if you access the same instance 2nd time, JspInit() would not be called. just <%= x++ %> would increment x by 1.
So the final value of x will be 3.[/QB]



Shouldn't it output 2 instead of 3?

<%= x++ %> ---> out.print(x++); // print x, then increment x
But:
<%= ++x %> ---> out.print(++x); // increment x, then print x


[Edit]
Sorry. It should output 3. I forgot to take into account the

at the end of the jsp.
[ April 13, 2007: Message edited by: Sergio Tridente ]
+Pie Number of slices to send: Send
Thanks guys!
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 939 times.
Similar Threads
Mock exam question doubt?
Mock exam question doubt?
_jspService methiod calarification
Question to an output
Mock exam question doubt?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:39:05.