I know this question has been asked in other languages including Java itself.
I just want to clarify that I know how to reverse an array but I would rather appreciate help if any for this particular solution of mine. So please don't mark it as a duplicate.
import java.util.Scanner;
class TestClass {
public static void main(String args[] ) throws Exception {
/*
Code for User input
*/
/* The problem was with the Swapping Code below */
for(int i=0; i<=n/2; i++)
swap(i,n-i-1,a);
/* Output Code. */
}
/*Swap function*/
public static void swap(int x, int y, int[] arr){
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
}
I have changed my solution according to the links provided in the comments .I am getting alright in some of the test cases but in some, the code fails.I think I have done it correctly.So any help will be appreciated.Thanks