Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 4402
251
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
% 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you do it in Java? What makes you think you can't use %?
 
Stefan Evans
Bartender
Posts: 1712
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic