Answers for "how to find the index of the smallest number in an array java"

2

how to find smallest number in array java

for(int i = 0;i<arr.length;i++){
	int min = arr[0];	
    if(arr[i]<min){
    	min = arr[i];
    }
    return min;  
}
Posted by: Guest on February-25-2022
-2

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

Code answers related to "how to find the index of the smallest number in an array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language