This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes The % operator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "The % operator" Watch "The % operator" New topic
Author

The % operator

deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
hi,
I understand that the % operator gives the remainder but I am not able to understand the result of a (smaller number % bigger number) for eg. 3%6 = 3. please help.

Thanks
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 78
% indicates the remander if you say 3%6..then just divide 3 with 6 ..so the remender will be 3 only
Panagiotis Kalogeropoulos
Rancher

Joined: May 27, 2011
Posts: 99

Every natural number y (eg 0,1,2,3....) can be described as:
y = a*x + b

In our case we can see that y = 3 and x = 6, so
3 = a*6 + b

When you use the % operator, it will give you the b variable of the above equation. And keeping in mind that we deal only with natural numbers, the result will be:
3 = 0*6 + 3

thus the result equals 3.

I hope this makes things a little more clear for you.
deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
Hi Eshwin,
Thanks for helping me. so 3/6 = 6X0+3 so answer is 3.
3/8 = 3x2+2 so answer is 2

am I right?

deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
sorry 3/8 = 8x0+3 answer is 3 right?
deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
Thanks Panagiotis I now understand this.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1295

Correct


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD)
Panagiotis Kalogeropoulos
Rancher

Joined: May 27, 2011
Posts: 99

No problem...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Panagiotis Kalogeropoulos wrote:Every natural number y (eg 0,1,2,3....) . . .
Surely that applies to every number, even members of ℝ, so Java™ can use the % operator on floating-point numbers, too.
Rumesh Eranga
Ranch Hand

Joined: Jan 26, 2011
Posts: 33
you got your answer from many people right??
deeps sinha
Greenhorn

Joined: Apr 20, 2012
Posts: 26
Thanks Everybody !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The % operator
 
Similar Threads
which lines of code will compile without erroe
Doh! I can't believe I don't know this....Square a number?
how to set a node on expression tree
Logical operator precedence
Problem with operator+