Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created February 21, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visparashar/859e93b6396886e6dfec5265e19ae2ed to your computer and use it in GitHub Desktop.
Save visparashar/859e93b6396886e6dfec5265e19ae2ed to your computer and use it in GitHub Desktop.
public class RotationArrayDemo {
public static void main(String[] args) {
int[] a ={1,2,3,4,5,6};
int d =2;
int temp[] =new int[d];
for(int i =0;i<a.length;i++){
if(i<d){
temp[i] =a[i];
}else{
a[i-d] =a[i];
}
}
for(int i =0;i<d;i++){
a[a.length-d+i] =temp[i];
}
for(int i =0;i<a.length;i++){
System.out.println(a[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment