Pros and Cons of declaring expression in java? “sum += i” instead of “sum = sum + i” [closed]
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 days ago . Improve this question I got this question in an interview that what's the impacts of declaring expression sum+=i; or sum = sum+i; inside the loop. int sum = 0; for (int i = 0; i <= 100; i++) { sum = sum + i; //Expression 1 sum += i; //Expression 2 } 回答1: In this example, there is no difference