Skip to content

Instantly share code, notes, and snippets.

@pepet96
Last active August 29, 2015 13:56
Show Gist options
  • Save pepet96/8969359 to your computer and use it in GitHub Desktop.
Save pepet96/8969359 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class LeftShift {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int [] arr = new int [a];
for (int i = 0; i < a; i++) {
arr[i] = input.nextInt();
}
int [] shiftarr = new int [a];
shiftarr = shift(arr);
for (int j = 0; j < shiftarr.length; j++) {
System.out.println(shiftarr[j] + " ");
}
}
public static int [] shift(int [] arr) {
int [] myArray = new int [arr.length];
myArray[arr.length-1] = arr[0];
for (int i = arr.length - 1; i > 0; i--) {
int x = i-1;
myArray[x] = arr[i];
}
return myArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment