Answers for "maximum difference in array"

0

maximum difference in array

public class maxDifference {

public static void main(String[] args) {
 
 int[] a = {1,4,8,15,17};
 
 int diff = 0;
 
 for(int i = 0; i < a.length-1 ; i++){
 
    if(a[i+1] - a[i] > diff)
   {
       diff = a[i+1] - a[i];
       
       }    
          }
 
 System.out.println(diff);
Posted by: Guest on January-22-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language