Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Provide an ADT java class for one-dimension arrays named “MyArray”

public void sum_elements(){
    int[] myArray = new int[3];
    myArray[0] = 1;
    myArray[1] = 3;
    myArray[2] = 5;
    int sum = 0;
    for (int i = 0; i < myArray.length; i++) {
        sum += myArray[i];
    }
    System.out.print(sum);
}
Source by brilliant.org #
 
PREVIOUS NEXT
Tagged: #Provide #ADT #java #class #arrays #named
ADD COMMENT
Topic
Name
3+9 =