Addition
You can add any two int
s using the +
operator.
void main() {
int x = 5;
// y will be 6
int y = x + 1;
// z will be 11
int z = x + y;
System.out.println(x);
System.out.println(y);
System.out.println(z);
}
Adding a negative number does the same thing as subtraction.
void main() {
int x = 5;
// y will be 1
int y = x + -4;
System.out.println(x);
System.out.println(y);
}