Tuesday, August 16, 2011

Java: what is %? and /=?

% is the modulus operator. It returns the remainder of division. 5%2 = 1 5/2 = 2 remainder 1. /= means divide and store. It first divides by the number after it the stores it back to the original variable. In this program it is a simpler way of writing "num = num / 2". The same idea applies to other operators like + - * and %, which are simplified as +=, -=, *=, an %=.

No comments:

Post a Comment