% operator on Long variable

Hi,

I’m writing a java service to get the quotient value. I need to get the value of quotient = (dividend % 10000), dividend is 16 digits. when I try to compile it says “operator % cannot be applied to java.lang.Long,int”

Can u guys help me out.

Thanks & Regards,
Rama

Can you please check if you have declared dividend as Long.

Thanks,
KVReddy

Quotient is the result of a division, which is the / operator.

The % operator will give you the remainder (often incorrectly called the modulus or modulo).
–Edit: http://mathforum.org/library/drmath/view/52343.html is a great thread on this explaining “The problem is that people tend to think of modulus as the same as remainder…” They are not.

You cannot use operators with any Java object (except + for String objects). There are two approaches to fix your code:

  1. Don’t create a java.lang.Long object in the first place. Just create a long primitive.

  2. Get the long primitive from the Long object by calling the longValue() method. e.g. remainder = (dividend.longValue() % 10000)