Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
622 B
4
Indexable
Never
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--;
        }
    }
}
Leave a Comment