Сумма всех чисел в массиве Java
int[] a = {10,20,30,40,50};
int sum = IntStream.of(a).sum();
System.out.println("The sum is " + sum);
Angry Antelope
int[] a = {10,20,30,40,50};
int sum = IntStream.of(a).sum();
System.out.println("The sum is " + sum);
public class Exercise2 {
public static void main(String[] args) {
int my_array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int sum = 0;
for (int i : my_array)
sum += i;
System.out.println("The sum is " + sum);
}
}
int [] arr = {1,2,3,4};
int sum = Arrays.stream(arr).sum(); //prints 10
class Main {
public static void main(String[] args) {
// Creating an array called x.
String[] x = new String[]{"This", "Should", "return", "4"};
// "x.length" finds the length of the array "x".
System.out.println(x.length);
// returns 4
}
}