title: adjacentElementsProduct task in CodeSignal problem - java
body: <p>I'm trying to solve this for 2 hours. That's task:
  Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.</p>
  
  <p>Example</p>
  
  <p>For inputArray = [3, 6, -2, -5, 7, 3], the output should be
  adjacentElementsProduct(inputArray) = 21.</p>
  
  <p>7 and 3 produce the largest product.</p>
  
  <p>And that's my solution.</p>
  
  <pre><code>int adjacentElementsProduct(int[] inputArray) {
  
      int[] tab = new int[29];
      int len = inputArray.length;
  
      for(int a = 0, int b = 1; a &lt; len; a++, b++)
      {
          tab[a] = inputArray[a] * inputArray[b];
      }
  
      int max = -100;
  
      for(int i = 0; i &lt; tab.length; i++)
      {
          if (tab[i] &gt; max)
              max = tab[i];
      }
  
      return max;
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/LjaOk.png" alt="That&#39;s screen with errors"></p>
  
  <p>Sure, i could find another (probably shorter) solution, but I'm curious why mine isn't working. Thanks.</p>
  
  <p>EDIT: Warning was because we are starting arrays from 0, not 1. So in my loops it will be
  inputArray.length - 1 
  instead of 
  inputArray.length
  I also tried to solve this another way, and that's my 2 solutions:</p>
  
  <pre><code>int adjacentElementsProduct(int[] inputArray) {
  
      int[] tab = new int[inputArray.length - 1];
  
      for(int a = 0; a &lt; inputArray.length - 1; a++)
      {
          tab[a] = inputArray[a] * inputArray[a+1];
      }
  
      int max = -10000000;
  
      for(int i = 0; i &lt; inputArray.length - 1; i++)
      {
          if (max &lt; tab[i])
              max = tab[i];
      }
  
      return max;
  }
  </code></pre>
  
  <p>And the second:</p>
  
  <pre><code>int adjacentElementsProduct(int[] inputArray) {
      int wynik = -1000;
      int mnozenie;
      for(int i = 0; i &lt; inputArray.length - 1; i++){
          mnozenie = inputArray[i] * inputArray[i+1];
          if(mnozenie &gt; wynik)
              wynik = mnozenie;
      }
      return wynik;
  }
  </code></pre>
  
  <p>but thanks for help @cricket_007 &amp; @AhmadWabbi :)</p>