Samridhi Gupta
08/01/2025
Finding Maximum and Minimum Value in an Array
The MaxMin program is a simple Java application that prompts the user to enter a number of elements and then the elements themselves. It calculates and displays the maximum and minimum values from the provided array of integers.
- Accepts user input for the number of elements in the array.
- Allows the user to input the elements of the array.
- Computes the maximum and minimum values from the array.
- Displays the results clearly.
- Java Development Kit (JDK) installed on your machine.
-
Clone the Repository (if applicable):
git clone https://github.com/Samridhi060/MinMax.git cd MaxMin -
Compile the Program: Open a terminal and navigate to the directory containing the
MaxMin.javafile. Then run:javac MaxMin.java
-
Run the Program: Execute the compiled Java program using:
java MaxMin
-
Input:
- When prompted, enter the number of elements in the array.
- Then, input each element of the array one by one.
-
Output: The program will display the maximum and minimum numbers from the array.
Enter the number of elements in the array:
5
Enter the elements of the array:
12
5
8
20
3
Maximum number is: 20
Minimum number is: 3
- The program begins by importing the
Scannerclass for user input. - It defines the
MaxMinclass, which contains themainmethod and themaxminmethod. - The
mainmethod handles user input and calls themaxminmethod. - The
maxminmethod iterates through the array to find the maximum and minimum values and prints them.
This program is a straightforward implementation to find the maximum and minimum values in an array of integers, demonstrating basic Java programming concepts such as arrays, loops, and user input.