Compound Assignment Operators
Compound Assignment Operators are just ways to quickly change the value of a variable. Here, we demonstrate the += operator, which helps us quickly add something to the variable on the left side.
int dayOfChristmas = 4; //initialize dayOfChristmas to 4
System.out.print("On the ");
System.out.print(dayOfChristmas);
System.out.println("th day of Christmas, my true love sent to me-");
//ONE WEEK LATER
System.out.println("One week later...");
dayOfChristmas += 7;
System.out.print("On the ");
System.out.print(dayOfChristmas);
System.out.println("th day of Christmas, my true love sent to me-");Output
On the 4th day of Christmas, my true love sent to me- One week later... On the 11th day of Christmas, my true love sent to me-