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

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 :: Add Elements in java map 
Java :: list of arrays 
Java :: java array 
Java :: string cannot be resolved to a type eclipse 
Java :: inorder traversal 
Java :: super 
Java :: abstract class java 
Java :: java meeting scheduler 
Java :: Java Access LinkedList elements 
Java :: Java How to use NavigableMap? 
Java :: java public keyword 
Java :: madhava kripa 
Java :: madrid 
Java :: empty map entry java 
Java :: android pick up photo from local device 
Java :: Java Using of() Method 
Java :: open cv for java 
Java :: how to pass parameters to xsl file 
Java :: internal hashcode 
Java :: for loop optimized java 
Java :: trémaux’ methode 
Java :: cfgbcfdxv 
Java :: mysqld always running 
Java :: Iterating & Adding to a Stack 
Java :: oxygen cylinder management program in java 
Java :: which exception is thrown when java is out of memory 
Java :: getBatteryPercentage android studio 
Java :: string.equals 
Java :: tipo map que permite armazenar na mesma chave java 
Java :: java webelement how to double click 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =