• Post Reply Bookmark Topic Watch Topic
  • New Topic

The % operator  RSS feed

 
deeps sinha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
% indicates the remander if you say 3%6..then just divide 3 with 6 ..so the remender will be 3 only
 
Panagiotis Kalogeropoulos
Rancher
Posts: 99
Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry 3/8 = 8x0+3 answer is 3 right?
 
deeps sinha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Panagiotis I now understand this.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct
 
Panagiotis Kalogeropoulos
Rancher
Posts: 99
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem...
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you got your answer from many people right??
 
deeps sinha
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Everybody !!!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!