Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

find the maximum and minimum values of an array.

public class Main {
public static void main(String[] args){
int[] numbers = {1,2,3,4};
System.out.println("This is your min value:");
getMinimum (numbers);
System.out.println("This is your max value:");
getMaximum (numbers);
}
private static void getMinimum (int[] arr) {
int min = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr.length < min) {
min = arr[i];
}
}
System.out.println(min);
}
private static void getMaximum (int[] arr) {
int max = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr.length > max) {
max = arr[i];
}
}
System.out.println(max);
}
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #maximum #minimum #values
ADD COMMENT
Topic
Name
7+4 =