java - How to increment an integer by reference? -
Is it possible to increase the value from a integer
value?
int counter A = 0; Int counterB = 0; Int counter = (condition)? Counter A: Counter B; // counter counter ++;
Result: Both Counter A + Counter B = 0, will be enlarged instead.
int
is a primitive type, therefore no reference is being assigned, Only values can you wrap it in a class:
public square IntegerHolder {Private int value; Public integerhold (int value) {this.value = value; } Public Zero Enhance () {value ++; } ...}
Comments
Post a Comment