在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);