Answers for "find maximum value in array java"

3

max in array java

// Initializing array of integers 
        Integer[] num = { 2, 4, 7, 5, 9 }; 
// using Collections.min() to find minimum element 
        // using only 1 line. 
        int min = Collections.min(Arrays.asList(num)); 
  
        // using Collections.max() to find maximum element 
        // using only 1 line. 
        int max = Collections.max(Arrays.asList(num));
Posted by: Guest on September-24-2020
0

find min in array java

private static int findMin(int[] array) {
		int min = array[0];
		for(int i=1;i<array.length;i++) {
			if(min > array[i]) {
				min = array[i];
			}
		}
		return min;
	}
Posted by: Guest on May-10-2020
1

find the maximum number from an int Array

---without sort method---
public static int maxValue( int[]  n ) {

int max = Integer.MIN_VALUE;

for(int each: n)

if(each > max)

max = each;

 
return max;
  
---with sort method---
public static int maxValue( int[]  n ) {

Arrays.sort( n );

return  n [ n.lenth-1 ];

}
Posted by: Guest on November-30-2020
1

maximum arrays size in java

int arr[] = new int[N];// Maximum Value Of N:2,147,483,647 (max int size)
Posted by: Guest on May-15-2020

Code answers related to "find maximum value in array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language