aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 60048
    
  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: 2885
    
  13

% 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
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60048
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to check if divisible by 2 in <c:if>
 
Similar Threads
JSTL tags
Different way of thinking about Leap
Problem with nested c:forEach
Returning if a number is prime. (Chapter on Objects and classes. OOP)
Check if list is empty jstl