-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramExamArrayMethodsPractice.java
More file actions
40 lines (36 loc) · 1.16 KB
/
Copy pathProgramExamArrayMethodsPractice.java
File metadata and controls
40 lines (36 loc) · 1.16 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
/*
* This program prompts
* @author {user}
* Course: COMP B11
* Created: Apr. 18, 2018
* Source File: ProgramExamArrayMethodsPractice.java
*/
import java.util.Arrays;
public class ProgramExamArrayMethodsPractice {
public static void main(String[] args) {
double[] anArray = { 1.2, 3.4, 5.6, 7.8, 9.10 };
processArray(anArray, 2.0);
System.out.println(Arrays.toString(anArray));
}
/**
* This method will check if an element resides in index that is EVEN or ODD
* if EVEN then will multiple the element by doubleGiven value, else ODD then
* the element at the given index will divided by doubleGiven. Then will put
* the value of the element back into the array and will return the array.
*
* @param array The array received when the method is called
* @param doubleGiven the double given by the to be used in the method
* @return The new array with its changed elements.
*/
public static double[] processArray(double[] array, double doubleGiven) {
for (int i = 0; i < array.length; i++) {
if (i % 2 == 0) {
array[i] *= doubleGiven;
}
else {
array[i] /= doubleGiven;
}
}
return array;
}
}