在Java中,可以使用以下方法快速將數字相加:
int sum = 3 + 5; // 將3和5相加,結果為8
int[] numbers = {1, 2, 3, 4, 5};
int sum = 0;
for (int i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
int[] numbers = {1, 2, 3, 4, 5};
int sum = Arrays.stream(numbers).reduce(0, (a, b) -> a + b);