How to find the largest number in an array in a Java program?

There are certain ways to determine the largest number in the Java program array. I have sorted several functions that you can implement.

First, you can use these functions:

public class MAX{
public static void main(String[] args){
int[] numbers = {3,4,5,7};
int max = 0;
for(int i=0;i<number.length;i++){
if(numbers[i] > max){
max = numbers[i];
}
}
System.out.println(“max number is = ” + max);
}
}
}
}

Or you can also manage working on these functions:

public double getHighestNum() {
this.highestNum = this.numbers[0];

for (int index = 1; index < this.numbers.length; index++)
{
if (this.numbers[index] > this.highestNum)
this.highestNum = this.numbers[index];
}
return this.highestNum;
}

If you don’t feel using the above functions, you can also use the following codes to find the largets number in the Java programming array.

mport java.util.*;
public class Largest{
public static void main(String args[])
{
int array[]={2,3,54,78,6};
Arrays.sort(array);
System.out.println(“the largest number is :”+array[(array.length)-1]);
}
}

Sorting the whole array improves the overhead. But if the size is small, it will not bother the strong hold processor.

I hope these helps you in defining the largest number. You can search for more functions if you don’t feel comfortable using these. You can check programming questions and answers and find any programming solutions you need with our help.