import java.util.Arrays; public class Swap { public static void main(String[] args) { int[] arr={1,2,3,4,5,6,7,8,9}; reverse(arr); // swap(arr,0,1); System.out.println(Arrays.toString(arr)); } static void swap(int[] arr,int a,int b){ int temp=arr[a]; arr[a]=arr[b]; arr[b]=temp; } static void reverse(int[] arr) { int start=0; int end=arr.length-1; while(start<end){ swap(arr,start,end); start++; end--; } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter