Switch first and last elements of an array Error
19:03 20 Nov 2013

For one of my methods, its role is to switch the first and last elements of an array. It worked just fine when I had the array built into the method. But then I decided to just have it read in an array from main and now it doesn't work right. It replaces different numbers each time or sometimes doesn't replace anything and just copies the array. Examples: 20432 20432 and 44413 44431 and 42203

    public static void main(String[] args) {

   int[] array = new int[5];
   int length = array.length; 
    for (int i = 0; i < length; i++) {
        array[i] = (int)(Math.random () * 5); 
        System.out.print(array[i]);
    }
    System.out.println("");
    flipFirstAndLast(array);
    replaceEvenWithZero(array);// TODO code application logic here
}
public static void flipFirstAndLast(int[] array){

    int i = array[0];
    int j = array[array.length - 1];


     int hold = array[i];
     array[i] = array[j] ;
     array[j] =  hold;
     for (int k = 0; k < 5; k++) {
         System.out.print(array[k]);
    }

     System.out.println("");
}
arrays netbeans switch-statement element