-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture21DoubleArray.java
More file actions
54 lines (50 loc) · 1.32 KB
/
Lecture21DoubleArray.java
File metadata and controls
54 lines (50 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
/**
* Lecture 21
* calling methods
* pass arguments by value
*
*
* @author PMCampbell
* @version 2020-12-01
*/
public class Lecture21DoubleArray {
public static void main(String[] args) {
double[] z = { 1.0, 2.0, 1.34567 };
double[] q = { 1.0, 3.0, 4.0 };
printArray(z, "Array z, before calling doubleMe() ");
doubleMe(z);
printArray(z, "Array z, after calling doubleMe() ");
printArray(q, "\nArray q, before calling doubleMe() ");
doubleMe(q);
printArray(q, "Array q, after calling doubleMe() ");
}
/**
* double the elements of an array
*
* @param array to be doubled
*/
public static void doubleMe(double array[]) {
for(int i=0;i<array.length;i++) {
array[i] = array[i] * 2;
// array[i] *= 2;
}
}
/**
* display contents of an array with {}
* from lab 19
*
* @param array array to be printed
* @param header header to print before array contents
*/
public static void printArray(double array[], String header) {
System.out.println(header);
System.out.print("{ ");
for(int i=0;i <array.length; i++) {
if (i == array.length-1) {
System.out.print(array[i]);
}else { System.out.print(array[i] + ","); }
}
System.out.println(" }");
}
}