Untitled
unknown
plain_text
2 years ago
622 B
8
Indexable
public class ReverseArray {
public static void main(String[] args) {
// Example usage
float[] array = {1.1f, 2.2f, 3.3f, 4.4f, 5.5f};
reverse(array);
System.out.println("Reversed array:");
for (float num : array) {
System.out.print(num + " ");
}
}
public static void reverse(float[] arr) {
int start = 0;
int end = arr.length - 1;
float temp;
while (start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
}Editor is loading...
Leave a Comment