public class Swapping{static void swap(int i,int j){int temp=i;i=j;j=temp;System.out.println("After swapping i = " + i + " j = " + j);}public static void main(String[] args){int i=1;int j=2;System.out.prinln("Before swapping i="+i+" j="+j);swap(i,j);}}
Output is they are swapped.
No comments:
Post a Comment