Created
December 24, 2023 17:45
-
-
Save mounicasrinivas/e1f161f7c534c0ea27c6f93ad49a2f75 to your computer and use it in GitHub Desktop.
Swapping An Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SwappingAnArray { | |
public static void main(String[] args) { | |
int [] a = {1,2,3,4,5}; | |
int n = a.length; | |
for(int i = 0; i< n/2; i++){ | |
// Swap numbers from ith and (n-1-i)th position; | |
int temp = a[n-1-i]; | |
a[n-1-i] = a[i]; | |
a[i] = temp; | |
} | |
for( int v : a){ | |
System.out.println(v + ""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment