0

When I was repairing a Project via Java that I did about a year ago I came across a piece of Code using n%7 and its a mystery to me what it does. What I understand what it exactly means - Not referring to %.

Thanks in advance,
DR

  • n modulus 7. if n=10 then n%7=3 , if n=5 then n%7=2 like this. – Drone Jan 30 '16 at 11:55
  • 1
    When people don't even bother to use Google... – Marco Bonelli Jan 30 '16 at 11:56
  • 2
    @MarcoBonelli - googling symbols and punctuation doesn't usually give good results. (Though googling "Java operators" works.) – nnnnnn Jan 30 '16 at 12:00
  • Is this question java or javascript? – Ferrybig Jan 30 '16 at 12:01
  • @Ferrybig : Both, as can be seen by tags. And if one can understand java mod operator, he/she can understand javascript's easily. – Faraz Jan 30 '16 at 12:03
  • 1
    I truly wish people would stop down voting so much. The guy/gal is obviously brand new to Stack with a rep of 4. Are you trying to prevent our community from growing? Explain why to question is not valid and what they should have done. I agree with @nnnnnn however I suspect the OP did not realize that this was even an operator. – Michael Hobbs Jan 30 '16 at 12:04
  • @MichaelHobbs I couldn't agree more. – Faraz Jan 30 '16 at 12:23
  • @MichaelHobbs: You misunderstand the goals of stackoverflow and the role of voting. Voting is the way to rate a *question* (or an answer), and is not a rating of the questioner. – President James K. Polk Jan 30 '16 at 12:36

1 Answers1

3

It is called modulus. It can be read as n modulus 7.

The MODULUS Operator %

The modulus operator finds the modulus of its first operand with respect to the second. That is, it produces the remainder of dividing the first value by the second value. For example:

22 % 6 = 4 because 22 / 6 = 3 with a remainder of 4

read more here: http://mathbits.com/MathBits/Java/DataBasics/Mathoperators.htm

Faraz
  • 4,939
  • 3
  • 18
  • 57