Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

sum of all numbers in array java

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

sum numbers 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);
}
}
Comment

sum of 1D array(JAVA)

import java.util.Arrays;
import java.util.Scanner;

public class LeetCode_RunningSum {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int[] arr = {1,2,3,4};

        System.out.println(Arrays.toString(out(arr)));

    }

    static int[] out(int[] nums){

        int sum = 0;
        int[] arr = new int[nums.length];

        for (int i = 0; i < nums.length; i++){
            sum += nums[i];
            arr[i] = sum;
        }

        return arr;
    }
}
Comment

how to find the sum of an array in java

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

java summe array

int[] A = {1, 2, 3};
int sum = 0;
for(int i = 0; i < A.length; i++){
	sum += A[i];
}
System.out.prinln(sum);//Ausgabe wäre in dem Beispiel: 6
Comment

Sum of Array Elements 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);
 }
}
Comment

java running sum of 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]
Comment

Finding the Sum of an Array in Java

    static int arr[] = { 12, 3, 4, 15 };
 
    // method for sum of elements in an array
    static int sum()
    {
        int sum = 0; // initialize sum
        int i;
 
        // Iterate through all elements and add them to sum
        for (i = 0; i < arr.length; i++)
            sum += arr[i];
 
        return sum;
    }
Comment

sum of array in java

Input : arr[] = {1, 2, 3}
Output : 6
1 + 2 + 3 = 6

Input : arr[] = {15, 12, 13, 10}
Output : 50
15 + 12 + 13 + 10 = 50
Comment

PREVIOUS NEXT
Code Example
Java :: how to read comma separated values in java 
Java :: matrix multiplication javascrpt 
Java :: can interface have attributes java 
Java :: convert double into integer 
Java :: how to print byte array in java 
Java :: this keyword in java 
Java :: setbackground java 
Java :: java  
Java :: java class name to string 
Java :: java inline conditional 
Java :: java loop using input user 
Java :: jbutton border size java 
Java :: final in java 
Java :: initialize a new class java 
Java :: retrofit post header 
Java :: java url 
Java :: spring boot access images in resources folder 
Java :: java mail use tls 1.2 
Java :: check if char is a space java 
Java :: java datatypes 
Java :: mouselistener in java 
Java :: set top corner of shape radius programmatically android 
Java :: how junit test getter and setter 
Java :: chenge font android studio 
Java :: There is no client authentication. Try adding an appropriate authentication filter 
Java :: sublist java 
Java :: java Overridding example 
Java :: spring-boot java header appliacation/json constant 
Java :: android dialogfragment fullscreen stack overflow 
Java :: how to convert line into string java 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =