For each loop find maximum and minimum

🔄 Loops Java Medium
🔄 Converted
Asked by Aamir Shaikh Jan 30, 2026 at 13:24 Subject: Object Oriented Programming(java)

Question:

create one array and pass to static function and find maximum and minimum using for each loop in java

💬 0 Comments 💡 1 Solution(s)

💡 Solutions (1)

✅ ACCEPTED SOLUTION

Aamir Shaikh

Jan 30, 2026 at 13:24

👍 1

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; } }

👍 Login to Vote

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!