@@ -30,6 +30,7 @@ public static void main(String[] args) {
3030 System .out .println (counts [i ]);
3131 }
3232
33+ // displaying arrays
3334 int [] array = {1 , 2 , 3 , 4 };
3435 printArray (array );
3536
@@ -49,9 +50,9 @@ public static void main(String[] args) {
4950 // copying with Arrays class
5051 double [] c = Arrays .copyOf (a , a .length );
5152
52- // traversal
53+ // traversing arrays
5354 for (int i = 0 ; i < a .length ; i ++) {
54- a [i ] = Math . pow ( a [i ], 2.0 ) ;
55+ a [i ] *= a [i ];
5556 }
5657
5758 // search
@@ -66,33 +67,33 @@ public static void main(String[] args) {
6667 /**
6768 * Prints the elements of an array.
6869 */
69- public static void printArray (int [] array ) {
70- System .out .print ("{" + array [0 ]);
71- for (int i = 1 ; i < array .length ; i ++) {
72- System .out .print (", " + array [i ]);
70+ public static void printArray (int [] a ) {
71+ System .out .print ("{" + a [0 ]);
72+ for (int i = 1 ; i < a .length ; i ++) {
73+ System .out .print (", " + a [i ]);
7374 }
7475 System .out .println ("}" );
7576 }
7677
7778 /**
7879 * Returns the index of the target in the array, or -1 if not found.
7980 */
80- public static int search (double [] a , double target ) {
81- for (int i = 0 ; i < a .length ; i ++) {
82- if (a [i ] == target ) {
81+ public static int search (double [] array , double target ) {
82+ for (int i = 0 ; i < array .length ; i ++) {
83+ if (array [i ] == target ) {
8384 return i ;
8485 }
8586 }
86- return -1 ;
87+ return -1 ; // not found
8788 }
8889
8990 /**
9091 * Returns the total of the elements in an array.
9192 */
92- public static double sum (double [] a ) {
93+ public static double sum (double [] array ) {
9394 double total = 0.0 ;
94- for (int i = 0 ; i < a .length ; i ++) {
95- total += a [i ];
95+ for (int i = 0 ; i < array .length ; i ++) {
96+ total += array [i ];
9697 }
9798 return total ;
9899 }
0 commit comments