Find out max and min value in array

package maxArray;

public class ArrayMax {

public static void main(String[] args) {
int[] arr = { 5, 12, 3, 19, 8 };
int max = 0;
for (int i = 0; i < arr.length; i++) {
if (max < arr[i]) {
max = arr[i];
}…


This content originally appeared on DEV Community and was authored by flevia g

package maxArray;

public class ArrayMax {

public static void main(String[] args) {
    int[] arr = { 5, 12, 3, 19, 8 };
    int max = 0;
    for (int i = 0; i < arr.length; i++) {
        if (max < arr[i]) {
            max = arr[i];
        }
    }
    System.out.println(max);

}

}

public class Minimum {

public static void main(String[] args) {
    int[] arr = { 10, 20, 30, 40, 5 };
    int min = arr[0]; // correct initialization

    for (int i = 0; i < arr.length; i++) {
        if (arr[i] < min) {
            min = arr[i];
        }
    }

    System.out.println("Minimum value: " + min);
}

}


This content originally appeared on DEV Community and was authored by flevia g


Print Share Comment Cite Upload Translate Updates
APA

flevia g | Sciencx (2025-07-25T11:59:16+00:00) Find out max and min value in array. Retrieved from https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/

MLA
" » Find out max and min value in array." flevia g | Sciencx - Friday July 25, 2025, https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/
HARVARD
flevia g | Sciencx Friday July 25, 2025 » Find out max and min value in array., viewed ,<https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/>
VANCOUVER
flevia g | Sciencx - » Find out max and min value in array. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/
CHICAGO
" » Find out max and min value in array." flevia g | Sciencx - Accessed . https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/
IEEE
" » Find out max and min value in array." flevia g | Sciencx [Online]. Available: https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/. [Accessed: ]
rf:citation
» Find out max and min value in array | flevia g | Sciencx | https://www.scien.cx/2025/07/25/find-out-max-and-min-value-in-array/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.