Answers for "get highest number in array java"

3

how to get the max value of an array java

public static double arrayMax(double[] arr) {
    double max = Double.NEGATIVE_INFINITY;

    for(double cur: arr)
        max = Math.max(max, cur);

    return max;
}
Posted by: Guest on May-10-2020
0

java function that returns the index of the largest value in an array

public int getIndexOfLargest( int[] array )
{
  if ( array == null || array.length == 0 ) return -1; // null or empty

  int largest = 0;
  for ( int i = 1; i < array.length; i++ )
  {
      if ( array[i] > array[largest] ) largest = i;
  }
  return largest; // position of the first largest found
}
Posted by: Guest on December-27-2019
0

java find biggest number in array

for (int counter = 1; counter < decMax.length; counter++)
{
     if (decMax[counter] > max)
     {
      max = decMax[counter];
     }
}

System.out.println("The highest maximum for the December is: " + max);
Posted by: Guest on February-15-2020

Code answers related to "get highest number in array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language