Input
Output
public class MaxInArray { public static void main(String[] args) { // Manually assigned array size and elements int n = 5; int[] arr = {10, 50, 30, 80, 25}; // Simulate input prompts and values System.out.println("Enter the number of elements in the array: " + n); System.out.println("Enter " + n + " integers:"); for (int i = 0; i < n; i++) { System.out.println(arr[i]); } // Initialize max with the first element int max = arr[0]; // Traverse the array to find the maximum for (int i = 1; i < n; i++) { if (arr[i] > max) { max = arr[i]; } } // Display the maximum element System.out.println("Maximum element in the array is: " + max); } }