“Summe der Array -Elemente Java” Code-Antworten

Summe aller Zahlen in Array Java

int[] a = {10,20,30,40,50};
int sum = IntStream.of(a).sum();
System.out.println("The sum is " + sum);
Angry Antelope

Summennummern in Array Java

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);
}
}
Biddls

So finden Sie die Summe eines Arrays in Java

int [] arr = {1,2,3,4};
int sum = Arrays.stream(arr).sum(); //prints 10
Motionless Moth

Java lauft Summe von Array

class Solution {
    public int[] runningSum(int[] nums) {
        int[] sol = new int[nums.length];
        sol[0] = nums[0];
        for(int i = 1; i < nums.length; i++) {
            sol[i] = sol[i-1] + nums[i];
        }
        return sol;
    }
}

// Example: runningSum([1,3,6,9]) = [1, 4, 10, 19] = [1, 1+3, 1+3+6, 1+3+6+9]
JunJun

Summe der Array -Elemente Java

// Calculate the sum of all elements of an array

class Main {
 public static void main(String[] args) {
  
   // an array of numbers
   int[] numbers = {3, 4, 5, -5, 0, 12};
   int sum = 0;

   // iterating through each element of the array 
   for (int number: numbers) {
     sum += number;
   }
  
   System.out.println("Sum = " + sum);
 }
}
SAMER SAEID

Ähnliche Antworten wie “Summe der Array -Elemente Java”

Fragen ähnlich wie “Summe der Array -Elemente Java”

Weitere verwandte Antworten zu “Summe der Array -Elemente Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen