Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Last active August 29, 2015 13:56
Show Gist options
  • Save JorgeOlvera/8969813 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/8969813 to your computer and use it in GitHub Desktop.
/*Returnanarraythatis"leftshifted"byone--so{6,2,5,3}returns{2,5,3, 6}. You may modify and return the given array, or return a new array.
shiftLeft({6, 2, 5, 3}) → {2, 5, 3, 6} shiftLeft({1, 2}) → {2, 1} shiftLeft({1}) → {1}
public int[] shiftLeft(int[] nums)
*/
import java.util.Scanner;
public class holyshift {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
System.out.println("Introduce size of array");
int limit = input.nextInt();
int [] array1 = new int [limit];
int [] array2 = new int [limit];
for (int i=0; i<limit; i++) {
array1[a] = input.nextInt();
}
array2 = arrayFlipper(array1);
for (int j=0; j<array2.length; j++) {
System.out.println(array2[j] + " ");
}
}
public static int[] arrayFlipper(int array1[], int limit) {
int[] array3 = new int[limit];
array3[0] = array1[array.lenght-1];
for (int j=1; j<array1.lenght; j++) {
int c=c-1;
array3[j] = array1[j];
}
return array3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment