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

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 Sum of Array Elements

// 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 :: get request java 
Java :: AmazonS3ClientBuilder 
Java :: java setbounds 
Java :: inorder, PreOrder, PostOrder java 
Java :: java arraylist loop 
Java :: how to acces every char of a String in java 
Java :: set remove element java 
Java :: android studio change title bar text 
Java :: java stream get list of one field 
Java :: how to print hello world java 
Java :: how to use random bound on doubles java 
Java :: in java how to throw exception from function 
Java :: get input in java using joptionpane 
Java :: android studio pass value to another activity 
Java :: Java how to make a number without a digit 
Java :: java list distinct by key 
Java :: modal css react 
Java :: Java Queue Array Implementation 
Java :: how to convert milliseconds into second in android studio 
Java :: printing 2d array in java 
Java :: java collapse string array 
Java :: print java 
Java :: Java print class type 
Java :: how to modify string in java 
Java :: java nested loop 
Java :: spring boot base url 
Java :: sudoku solver 
Java :: how to get current date in java 
Java :: hadoop-master error java_home is not set and could not be found 
Java :: test a javafx project 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =