Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1.      /**
  2.       * Help method for secondMax
  3.       */
  4.      private int helpSecondMax(int[] v, int max, int index) {
  5.          while (index < v.length) { // vill du ha en while-loop här, det är ju typ vad man gör när man räknar iterativt?
  6.             if (max < v[index]) {
  7.                 max = v[index];
  8.             }
  9.             helpSecondMax(v, max, (index+1)); // notera att metodens index inte ändras här, bara att det anropas igen med ett nytt index. variabeln index ändras alltså aldrig.
  10.          }
  11.         return max;
  12.      }
  13.      
  14.      /**
  15.       * My second method for finding the largest value in an array
  16.       */
  17.      public int secondMax(int[] v) {
  18.          return helpSecondMax(v, 0, 0);
  19.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement