What is the longhand of sum += value;
assignment operator in this java code example:
package com.company;
public class Temp {
public static void main(String[] args) {
var i1 = 10;
var i2 = 20;
System.out.println("Result of two : " + totalSum(i1, i2));
System.out.println("Result of multiple: " + totalSum(i1, i2, i1, i2));
}
public static double totalSum(int... values) {
int sum = 0;
for (int value : values) {
sum += value; // result = 60 (Correct output)
/*
*
* sum = value = value + value; // if this ! result is = 40 sum = value + value;
* // if this ! result is = 40
*
*/
}
return sum;
}
}
CONSOLE OUTPUT:
Result of two : 30.0
Result of multiple: 60.0