Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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

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 :: Java, how to compare Strings with String Arrays 
Java :: Do not concatenate text displayed with setText. Use resource string with placeholders. 
Java :: java map to list or array 
Java :: java print 2d char array 
Java :: contains hashmap java 
Java :: java variable in string 
Java :: retrofit implementation 
Java :: java singleton implementation 
Java :: Java make digit numbers 
Java :: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message) 
Java :: frequency of each element from list in java 
Java :: how to resize image in java swing 
Java :: return the maximum sum of two numbers whose digits add up to an equal sum 
Java :: print list array 
Java :: java get bigger int 
Java :: running sum of 1d array java 
Java :: get the max value from arrayList java and save it in int 
Java :: validate date java 
Java :: java comments 
Java :: copy elements of array in java 
Java :: intent pick action video android 
Java :: java bean 
Java :: array sort java 
Java :: How to build a Sudoku solver, in Java? 
Java :: java string array initialization 
Java :: java stream get all max values 
Java :: jbutton open jframe java 
Java :: each character in string java 
Java :: how generate a random number in java between 3 and 5 
Java :: reverse in jaav 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =