I am still learning Java and have a question on an array.
My array:
double arr[] = {1.8, 3.6, 5.0, 2.0};
My question is how do I divide the first index by the next and so on, but not the last index.
Each index is to be divided by 2. So that the resulting array looks like this:
double arr[] = {0.5, 0.72, 2.5, 2.0};
I am on the right track by proceeding this way:
public static void main(String [] args){
double arr[] = {1.8, 3.6, 5.0, 2.0};
for(int j = 0; j < arr.length; j++){
arr[j] = arr[0] / arr[1];
arr[j] = arr[1] / arr[2];
System.out.println(arr[j]);
}
}
I am not sure how to proceed and all help is appreciated.
Thank you.
try this:
`