Skip to content

Commit

Permalink
Add java language code solution and its image for the AdjacentElement…
Browse files Browse the repository at this point in the history
…sProduct challenge
  • Loading branch information
Brnd08 committed Jul 18, 2023
1 parent 86b73f3 commit f95a326
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions AdjacentElementsProduct/Adjacent_elements_product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Arrays;
public class Adjacent_elements_product{
public static void main (String args[]){
int testArray [] = new int[] {3, 6, -2, -5, 7, 3};
System.out.format(" The max adjacent numbers product for the array %s is %d %n", Arrays.toString(testArray), solution(testArray));
int testArray2 [] = new int[] {1, 0, 1, 0, 1000};
System.out.format(" The max adjacent numbers product for the array %s is %d %n", Arrays.toString(testArray2), solution(testArray2));
}
static int solution(int[] inputArray) {
int maxProduct = inputArray[0]*inputArray[1];
for(int i = 2; i<inputArray.length; i++){
int currentProduct = inputArray[i]* inputArray[i-1];
if(currentProduct > maxProduct)
maxProduct= currentProduct;
}
return maxProduct;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f95a326

Please sign in to comment.