title: Print last occurrence (printing mistake)
body: <pre><code>public class TestForMatch2
  {
      public static void main(String[] args)
      {
          int[] numbers1 = {0,2,4,6,7,11,0};
          int[] numbers2 = {-7,5,9,10,5,0};
          System.out.println(findTarget(numbers1,5));
          System.out.println(findTarget(numbers1,0));
          System.out.println(findTarget(numbers2,5));
          System.out.println(findTarget(numbers1,-1));
      }
      public static int findTarget(int[] arr, int target)
      {
          if (arr == null) {
              return -1;
          }
          int y = 0;
          int g = 0;
          for(int i = 0; i &lt;= arr.length-1; i++) {
              if (target == arr[i]) {
                  y = i;
                  //return y;
              }
          }
          System.out.println(y);
          return -1;
      }
  }
  
  Output:
  0
  -1
  6
  -1
  4
  -1
  0
  -1
  </code></pre>
  
  <p>As you can see, there is a -1 that is being printed. If I remove the return -1, it gives me an error. How to remove the -1 without the error? </p>
  
  <p>This is what is to be done. </p>
  
  <p>Write a Java method to test if an array of integers contains a specific value.
  If the value is in the array, returns the index of the element. If the value is more than once the method will return the index of the last occurrence of the value. 
  If the value is not in the array, returns -1.</p>
  
  <p>Copy and paste the following code. Then complete the method.</p>
  
  <pre><code>public class Main
  {
      public static void main(String[] args)
      {
          int[] numbers1 = {0,2,4,6,7,11,0};
          int[] numbers2 = {-7,5,9,10,5,0};
          System.out.println(findTarget(numbers1,5));
          System.out.println(findTarget(numbers1,0));
          System.out.println(findTarget(numbers2,5));
          System.out.println(findTarget(numbers1,-1));
      }
      public static int findTarget(int[] arr, int target)
      {
          //Type your code here
      }
  }
  </code></pre>
  
  <p>This is the desired result. Ignore the numbers on the left. I put it there to emphasise on the space on number 5. Thank you for your time.</p>
  
  <pre><code>  1  -1
    2  6
    3  4
    4  -1
    5
  </code></pre>