Write a Java method to print the maximum and minimum value of an array containing elements [7,20,29,0,4,30,24,100]
JAVA CODE :
import java.util.*;
public class Main
{
public static void printMaxiMini(int a[])
{
Arrays.sort(a); // sorts the array
System.out.println("Minimum : " + a[0]); // print minimum
value
System.out.println("Maximum : " + a[a.length - 1]); // print
maximum value
}
public static void main(String[] args) {
int a[] = {7, 20, 29, 0, 4, 30, 24,
100}; // initialize the array elements
printMaxiMini(a); // call
printMaxiMini
}
}
OUTPUT :
Get Answers For Free
Most questions answered within 1 hours.