Meant to be written in Java JDK 14.0
Generate four (4) integer numbers in range [0, 100]. Use Math methods to: (a) find the maximum and minimum numbers and display (b) calculate the absolute difference between the maximum number and minimum numbers, display
import java.util.Random; public class FourRandom { public static void main(String[] args) { Random random = new Random(); int n1 = random.nextInt(101); int n2 = random.nextInt(101); int n3 = random.nextInt(101); int n4 = random.nextInt(101); System.out.println("Random numbers generated are " + n1 + ", " + n2 + ", " + n3 + " and " + n4); int max = Math.max(Math.max(n1, n2), Math.max(n3, n4)); int min = Math.min(Math.min(n1, n2), Math.min(n3, n4)); System.out.println("Maximum: " + max); System.out.println("Minimum: " + min); System.out.println("Difference between maximum and minimum is " + Math.abs(max - min)); } }
Get Answers For Free
Most questions answered within 1 hours.