package JAVA;
import java.util.Scanner;
public class Assignment4 {
public static void main(String[] args) {
// Create a Scanner object for reading input
Scanner scanner = new Scanner(System.in);
// Prompt to enter the number of students
System.out.print("Enter num of students: ");
int numStudents = scanner.nextInt();
// Initialize total height, tallest and shortest height
double totalHeight = 0, tallest = Double.MIN_VALUE, shortest = Double.MAX_VALUE;
for (int i = 1; i <= numStudents; i++) {
double height;
// Ensure the height is non-negative
do {
System.out.print("Enter student " + i + " height: ");
height = scanner.nextDouble();
if (height < 0) {
System.out.println("Invalid height, re-enter!");
}
} while (height < 0);
// Accumulate the height, update the tallest and shortest height
totalHeight += height;
tallest = Math.max(tallest, height);
shortest = Math.min(shortest, height);
}
// Calculate and print the average height, tallest height and shortest height
double average = totalHeight / numStudents;
System.out.println("Average height: " + average);
System.out.println("Tallest height: " + tallest);
System.out.println("Shortest height: " + shortest);
// Close the Scanner
scanner.close();
}
}