Reverse the order of the given double value type array in Java
Description
The following code shows how to reverse the order of the given double value type array.
Example
// www . j av a 2s. co m
import java.util.Arrays;
public class Main {
public static void main(String[] argv){
double[] data = new double[]{1.1,2.1,3.1,4.1,5.1};
System.out.println(Arrays.toString(data));
reverse(data);
System.out.println(Arrays.toString(data));
}
public static void reverse(double[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
double tmp;
while (j > i) {
tmp = array[j];
array[j] = array[i];
array[i] = tmp;
j--;
i++;
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »