I am new to Java, actually programming in general. I understand that the modulus operator (%) returns the remainder of two numbers, however, I do not understand why 17 % 40 = 1
If you have the numbers a and b, their quotient q and remainder r, then the following has to be true:
q · b + r = a
That is, if you multiply the quotient (q) by the divisor (b) and add the remainder (r), the result is the dividend (a).
In your case a = 17, b = 40, q = 0 and so r has to be 17.
Note: the equation above is just a rearrangement of the equation from Nikolay Kuznetsov's answer, but I think it's easier to understand this way.