java - How to shift an array to the left? -


it compiles properly, when runs, prints array of numbers bunch of errors. how have method leftshift shift left?

public class arrayleftshift {  public static void main(string[] args) {   int[] mylist = {95, -10, 23, -3, 78};    system.out.print("mylist: ");   printarray(mylist);    leftshift(mylist);   system.out.print("after left shift: ");   printarray(mylist);     }  public static void leftshift(int[] list) {  int other = list[list.length+1];  (int = list.length+2; >= 0; i++)   list[i-1] = list[i];  list[0] = other; system.out.print("\nshifted array: "); }  public static void printarray(int[] list) { (int d: list)    system.out.print(d + " "); system.out.println(); }  } 

public static int[] leftshift(int[] a) {     int[] r = new int[a.length];     (int = 0; < a.length - 1; i++)         r[i] = a[i+1];     r[a.length - 1] = a[0];     return r; } 

if want shift left , wrap first value end should work....


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -