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

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 :: print map in java 
Java :: java read file bufferedreader 
Java :: groovy string to json 
Java :: java code examples 
Java :: is prime java 
Java :: How to compare lists of custom classes without defining equals() and hashCode()? 
Java :: find duplicate value in array java 
Java :: abstract vs final 
Java :: spring boot jpa in clause 
Java :: spring @Bean destroyMethod 
Java :: find object with same attribute java stream 
Java :: java do while schleife 
Java :: android studio textview set text int 
Java :: java queue 
Java :: get logged-in user in Spring Security 
Java :: java swing alert window 
Java :: What is unreachable catch block error? 
Java :: java how to make a gui 
Java :: how to iterate hashmap java 
Java :: java filedialog 
Java :: get hashmap into array 
Java :: scanner check if int 
Java :: java remove duplicates from list by property 
Java :: sort 2d array by column java 
Java :: do while loop in java 
Java :: sorting an arraylist 
Java :: android translate string java 
Java :: main methode java 
Java :: how to compare current date and time with another date and time in android 
Java :: jframe border 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =