title: Trying to display the last index of a item in array Java
body: <p>I am trying to display the last index of an item in array, an example:</p>
  
  <p><code>{6,4,7,3,11,4} Last index of 4 = 5</code></p>
  
  <p>I have written this method so far: </p>
  
  <pre><code>public int lastIndexOf(int[] nums, int num) {
          int found = 0;
          for (int i = nums.length; i &lt; 0 ; i--) {
              if (nums[i] == num) {
                  return i;
              }
          }
          return -1;
  
      }
  </code></pre>
  
  <p>Why does this not work? I am under the impression that you need to start the for loop at the start of the arrays length and then work backwards. I want to be able to use a for loop to do this, I set up a condition if there are no occurrences of the number to return -1 but when I am running this code I always return -1 no matter what numbers I am putting in.</p>
  
  <p>How would I solve this using a for loop?</p>