title: java return array in method
body: <p>I'm doing my first steps in java, so my question is simple - I have an array with 8 integers and I want to return an array that contains the odd index elements from the original array. what's wrong with the method deceleration? Any other implementation tips would be appreciated.</p>
  
  <p>P.S - I know that I don't have to use method here, it's just for the exercise. </p>
  
  <pre><code>package com.tau;
  
  public class Main {
  
  
      public static void main(String[] args) {
  
          int[] arr = {1, 2, 3, 4, 5, 6, 7, 8};
  
  
          System.out.println("1.e odd index numbers in array : " + oddIndex(arr));
  
          int j = 0;
          public static int[] oddIndex(int[] array){
              int newArrSize = array.length;
              if ((newArrSize % 2) != 0) {
                  newArrSize--;
              }
  
              int[] newArr = new int[newArrSize];
  
              for (int i = 0; i &lt; array.length; i++)
                  if ((array[i] % 2) == 0) {
                      newArr[j] = array[i];
                      j++;
                  }
              return newArr;
  
        }
      }
  
  
  } 
  </code></pre>