dcsimg
Embarrasing that I can't get it to work
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aaron_Keane
Posted On:   Monday, August 13, 2001 04:22 AM

I am trying to use the Modulus operator in JSP, and it doesn't seem to want to work.


What I am using is

			
"result = variable % expression"


As far as I can make out this should work for me, but it isn't, does anyone have any ideas as to what I am doing wrong?

Re: Embarrasing that I can't get it to work

Posted By:   Joe_Pollard  
Posted On:   Tuesday, August 14, 2001 11:27 PM

That should work as long as you are using ints. If you aren't using ints, then modulus really doesn't make since as an operator.

public class tmp {
public static void main(String [] s) { new tmp(); }
public tmp() {
int variable = 50;
int expression = 4;
int result = variable % expression;
System.out.println(result);
}
}

Take a look at the specification of this operator at http://java.sun.com/docs/books/jls/first_edition/html/15.doc.html#24956 . If you still have questions, please post your error message and code and we'll help you fix it.... Hope that helps!

-Joe

Re: Embarrasing that I can't get it to work

Posted By:   Mathias_Neuhaus  
Posted On:   Monday, August 13, 2001 07:54 AM

just a guess...

Put expression in parenthesis.
About | Sitemap | Contact