Advertisement
JeffGrigg

max product of array -- ArrayIndexOutOfBoundsException

Aug 22nd, 2017
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.57 KB | None | 0 0
  1. public class hello {
  2.  
  3.     private static int adjacentElementsProduct(int[] inputArray) {
  4.         int sum = inputArray[0] * inputArray[1];
  5.         for (int index = 1; index <= inputArray.length - 1; ++index) {
  6.             final int product = inputArray[index] * inputArray[index + 1];
  7.             if (product >= sum)
  8.                 sum = product;
  9.         }
  10.         return sum;
  11.     }
  12.  
  13.     public static void main(String[] args) {
  14.         int[] numo = {3, 6, -2, -5, 7, 3};
  15.         int h = hello.adjacentElementsProduct(numo);
  16.         System.out.println(h);
  17.     }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement