Java Reference
In-Depth Information
System.out.println("Line 19: The position of "
+ "the largest element in "
+ "listA is: "
+ OneDimArrayMethods.indexLargestElement
(listA, listA.length));
//Line 19
//find and output the largest element in listA
System.out.println("Line 20: The largest element "
+ "in listA is: "
+ listA[OneDimArrayMethods.indexLargestElement
(listA, listA.length)]);
//Line 20
//copy the elements of listA into listB
//using the method copyArray
OneDimArrayMethods.copyArray(listA, 0, listB, 0,
listA.length);
//Line 21
System.out.print("Line 22: After copying the "
+ "elements of listA into listB\n"
+ "
listB elements are: ");
//Line 22
//output the elements of listB
OneDimArrayMethods.printArray(listB,
listB.length);
//Line 23
System.out.println();
//Line 24
} //end main
//Line 25
}
//Line 26
Sample Run: (In this sample run, the user input is shaded.)
Line 9: listA elements: 0 0 0 0 0 0 0 0 0 0
Line 12: Enter 10 integers: 33 77 25 63 56 48 98 39 5 12
9
Line 15: After filling listA, the elements are:
33 77 25 63 56 48 98 39 5 12
Line 18: The sum of the elements of listA is: 456
Line 19: The position of the largest element in listA is: 6
Line 20: The largest element in listA is: 98
Line 22: After copying the elements of listA into listB
listB elements are: 33 77 25 63 56 48 98 39 5 12
The statement in Line 7 creates the array listA of 10 elements and initializes each
element of listA to 0 . Similarly, the statement in Line 8 creates the array listB of 10
elements and initializes each element of listB to 0 . The statement in Line 10 calls the
method printArray and outputs the values stored in listA . The statement in Line 13
calls the method fillArray to input the data into array listA . The statement in Line 18
calls the method sumArray and outputs the sum of all the elements of listA . The
statement in Line 19 calls the method indexLargestElement to find the index of (the
first occurrence of) the largest element in listA . Similarly, the statement in Line 20
outputs the value of the largest element in listA . The statement in Line 21 calls the
method copyArray to copy the elements of listA into listB , and the statement in
Line 23 outputs the elements of listB .
Search WWH ::




Custom Search