wood burning stoves 2.0*
The moose likes JSP and the fly likes how to check if divisible by 2 in <c:if> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to check if divisible by 2 in <c:if>" Watch "how to check if divisible by 2 in <c:if>" New topic
Author

how to check if divisible by 2 in <c:if>

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Hi i am trying to check a condition if its divisible by two using

but looks like % jstl doesn't recognize % any idea how i can check if something is divisible by two
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Rajesh Khan wrote:
but looks like % jstl doesn't recognize % any idea how i can check if something is divisible by two

This has nothing to do with the JSTL but the EL.

And what evidence leads you to believe this?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Yep.. sorry I mean EL.
Any idea how i can check if a number is divisible by 2 using <c:if> tag ??
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3019
    
  35

% and mod are modulus operators in EL. In other words, it returns the result of the given modulo operation, which is NOT a boolean value.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

How would you do it in Java? What makes you think you can't use %?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
1 % 2 == 1
2 % 2 == 0
3 % 2 == 1
4 % 2 == 0
...
10 % 2 == 0
11 % 2 == 1

Perhaps the check you want is "count % 2 == 0" ?
In some languages a check of "if (count % 2)" is sufficient, because zero gets interpreted as false in that language.
This is not the case in EL though. You need to make the comparison to zero explicitly.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to check if divisible by 2 in <c:if>
 
Similar Threads
Problem with nested c:forEach
Check if list is empty jstl
Returning if a number is prime. (Chapter on Objects and classes. OOP)
JSTL tags
Different way of thinking about Leap