public class ModAndInce /** This class demonstrates % and ++ in Java and += * */ { public static void main(String[] args) { // Introducing the MODULUS operator defined on integers int rem=7%3; // answer is 1. 7/3 is 2 R 1 and the remainder is answer to modulus System.out.println("7%3=" + rem); rem=21%12; // answer is 9 System.out.println("21%12=" + rem); // rem=21.5%6; // modulus is not defined on doubles (compiler error) // We often use modulus to check for divisiblity. A remainder of zero // means that the number is divisible int x; x=x+1; x+=1; // for adding a value to a variable x+=5; // to add 5 to x x++; // increment operator NOT the same as x+1,it is the same as x=x+1 ++x; } }