Java code for above problem
class Main
{
public static void main(String args[])
{
System.out.println(diff(new
int[]{1,2,3,4,5})); // prints
"4"
}
public static int diff(int arr[])
{
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
for(int
i=0;i<arr.length;i++)
{
max=Math.max(max,arr[i]);
min=Math.min(min,arr[i]);
}
return max-min;
}
}
Mention in comments if any mistakes or errors are found. Thank you.
Get Answers For Free
Most questions answered within 1 hours.