title: Difference in integers in an array JAVA
body: <p>I was working on a problem and got stuck. Here is the problem.</p>
  
  <p>You are walking along a hiking trail. On this hiking trail, there is elevation marker at every kilometer. The elevation information is represented in an array of integers. For example, if the elevation array is [100, 50, 20, 30, 50, 40], that means at kilometer 0, the elevation is 100 meters; at kilometer 1, the elevation is 50 meters; at kilometer 2, the elevation is 20 meters; at kilometer 3, the elevation is 30 meters; at kilometer 4, the elevation is 50 meters; at kilometer 5, the elevation is 40 meters.</p>
  
  <p>b) Write a method called longestUphill that returns the elevation change in meters of the longest uphill section. In the example above, the method should return 30 because the longest uphill section is from kilometer 2 with 20 meters to kilometer 4 with 50 meters. The elevation change is 50 - 20 = 30 meters.</p>
  
  <p>Here is what I have so far.</p>
  
  <pre><code>public int longestUphill(int[] elevation)
  {
      int end,longest=0;
      for(int i=0;i&lt;elevation.length-1;i++){
      end = i+1;
      while(elevation[end]-elevation[i]&gt;=0){
          end++;
      }
      if(elevation[end]-elevation[i]&gt;longest) longest = elevation[end]-elevation[i];
  }
  return longest;
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks!</p>