Skip to content

Commit ca7b116

Browse files
committed
feat: Add ShortcutOperators class demonstrating compound assignment and increment/decrement
Add a class to illustrate shortcut operators in Java including: - Post-increment (x++) and post-decrement (z--) - Compound addition (y += x) - Compound multiplication (z *= x - y) - Step-by-step output showing value updates.
1 parent 4e03ff4 commit ca7b116

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Section5OperatorExpression/1. Fundamentals/Operators/Shortcut Operators/src/ShortcutOperators.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ public class ShortcutOperators
33
public static void main(String[] args)
44
{
55
int x = 1, y = 3, z = -2;
6+
67
x++; //x is incremented by 1
78
System.out.println("x is now " + x);
9+
810
z--; //z is decremented by 1
911
System.out.println("z is now " + z);
12+
1013
y += x; //y increases by the current value of x
1114
System.out.println("y is now " + y);
15+
1216
z *= x-y; //z gets multiplied by the difference between x and y
1317
System.out.println("z is finally " + z);
1418
}
15-
}
19+
}

0 commit comments

Comments
 (0)