We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
class Difference {
private int[] elements;
public int maximumDifference;
public Difference(int [] b){
this.elements=b;
}
// Add your code here
public int computeDifference(){
Arrays.sort(elements);
maximumDifference=elements[elements.length-1] -elements[0];
return maximumDifference;
}
} // End of Difference class
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
sc.close();
Difference difference = new Difference(a);
difference.computeDifference();
System.out.print(difference.maximumDifference);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 14: Scope
You are viewing a single comment's thread. Return to all comments →
Java: import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
class Difference { private int[] elements; public int maximumDifference; public Difference(int [] b){ this.elements=b; }
} // End of Difference class
public class Solution {
}