Created
October 25, 2015 17:39
-
-
Save edinak1/e5a002deac76270f2dd7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package masiv; | |
| public class Swap { | |
| public static void main(String[] args) { | |
| int [] data={1,10,5,7,6}; | |
| int [] data1={0}; | |
| int [] data2={}; | |
| int [] data3={0,0,15,25,16}; | |
| int [] data4={-3,25,2}; | |
| swap(data ); | |
| swap(data1); | |
| swap(data2); | |
| swap(data3); | |
| swap(data4); | |
| printArray(data ); | |
| printArray(data1); | |
| printArray(data2); | |
| printArray(data3); | |
| printArray(data4); | |
| } | |
| static void swap(int[]data) | |
| { | |
| if(data==null || data.length<=1) | |
| return; | |
| int temp; | |
| for(int i=0;i<data.length-1;i++) | |
| { | |
| temp=data[i]; | |
| data[i]=data[i+1]; | |
| data[i+1]=temp; | |
| } | |
| } | |
| static void printArray(int[]data) | |
| { | |
| if(data==null) | |
| return; | |
| int i=0; | |
| System.out.print("["); | |
| while(i!=data.length) | |
| { | |
| System.out.print(data[i]); | |
| i++; | |
| if(i<data.length) | |
| System.out.print(","); | |
| } | |
| System.out.println("]"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment