Hi, While appearing in Marcus Green's quiz question no.5 of EL chapter <%int i = 1;int j =2;%> ${i < j} ${1 lt 2}
I was expecting answer as "true true" but right answer is "false true"
Can anyone please explain why ${i < j} will evaluate to false?
Thanks in advance [ May 06, 2008: Message edited by: Gurukant Desai ]
Musab Al-Rawi
Ranch Hand
Joined: Aug 06, 2007
Posts: 231
posted
0
hi,
if i am not mistaken <%int i = 1;int j =2;%> these are variables not attributes. with the EL you can access attributes of four scopes. so ${i} and ${j} are not defined ... so they are treated as zero. So ${0 < 0} that's false because zero is equal to zero.
SCBCD - SCWCD - SCJD - SCJP - OCA
Padma priya Gururajan
Ranch Hand
Joined: Oct 05, 2006
Posts: 411
posted
0
Hi, Any correct solutions to the problem? Thanks in advance.
Padma priya N.G.
Be the change you want to be - Mahatma Gandhi
Kumar Garlapati
Ranch Hand
Joined: Feb 04, 2008
Posts: 38
posted
0
Musab is absolutely correct with bit change in the explaination, except that zero, it doesn't evaluates as zero. It evaluates as blank.
If it evaluates as zero, ${i==j}, should return true, but it's returning as false. i tried.
output is : true If we remove scriplet from above code, then output is : false. it means that if i and j are not present in any scope, they are unable to evaluate as any values. so its evaluating as false. [ May 06, 2008: Message edited by: Kumar Garlapati ]
Regards,<br />Kumar
Musab Al-Rawi
Ranch Hand
Joined: Aug 06, 2007
Posts: 231
posted
0
with EL null evaluates to false in boolean expressions and to zero in arithmetic operations.