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 :: android maven dependency 
Java :: hexstring to string In java 
Java :: delete one item from list recycleview 
Java :: reverseString 
Java :: HOW TO PARSE a string into a number in java 
Java :: Java Sorting Using sort() 
Java :: print string in java 
Java :: apache commons collections android dependency 
Java :: what does setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) is used for 
Java :: how to change color of drawable in android 
Java :: add element in the last in double linked list in java 
Java :: java first character string number 
Java :: how to get current time and date in android 
Java :: Java Longest String In String Array 
Java :: java add element to existing array 
Java :: java to the power of 
Java :: java leap years 
Java :: how to convert a string to char in java 
Java :: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId; 
Java :: convert java to python 
Java :: splay tree java implementation 
Java :: elif java 
Java :: how to get elements of a list in java 
Java :: java array sorting java8 
Java :: regular expression java 
Java :: java 8 stream option 
Java :: how to convert string to int in java 
Java :: java hash map 
Java :: spring xml configuration 
Java :: spring @value default value 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =