Reverse the order of the given float type value array in Java
Description
The following code shows how to reverse the order of the given float type value array.
Example
/* w w w . ja va 2s.c om*/
import java.util.Arrays;
public class Main {
public static void main(String[] argv){
float[] data = new float[]{1.1f,2.1f,3.1f,4.1f,5.1f};
System.out.println(Arrays.toString(data));
reverse(data);
System.out.println(Arrays.toString(data));
}
public static void reverse(float[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
float 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 »