For each loop find maximum and minimum
Question:
create one array and pass to static function and find maximum and minimum using for each loop in java
💡 Solutions (1)
Aamir Shaikh
Jan 30, 2026 at 13:24
upvotes
class foreachloop1 { public static void main(String[] args) { int[] marks = {125, 132, 95, 116, 110}; int max = findMax(marks); int min = findMin(marks); System.out.println(max); System.out.println(min); } static int findMax(int[] arr) { int maximum = arr[0]; for (int value : arr) { if (value > maximum) { maximum = value; } } return maximum; } static int findMin(int[] arr) { int minimum = arr[0]; for (int value : arr) { if (value < minimum) { minimum = value; } } return minimum; } }
Want to add your solution? Login to contribute!
🔄 This question has been converted to a program
View Program →💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!