gpt-4-0125-preview· OpenAI
WildChat-4.8M (AI2)
Create a question and test the content below in this format. [ Question body Responses…
- User
Create a question and test the content below in this format. [ Question body Responses (or correct response if it is a complete the code or find the error) Explanation of the correct answer Tip Difficulty (easy, medium, hard) ]. Content: Reverse order an array(java)
- Assistant
Question Body: Write a Java program to reverse the order of elements in an array.
Responses:
javapublic class ReverseArray { public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; int n = arr.length; // Reverse the array for (int i = 0; i < n / 2; i++) { int temp = arr[i]; arr[i] = arr[n - 1 - i]; arr[n - 1 - i] = temp; } // Print the reversed array for (int i : arr) { System.out.print(i + " "); } } }