java program to find largest number in an array

By | April 26, 2020

Java program to find largest number in an array:

In this article, you are going to learn how to find the largest number in an array in java by giving the input elements from the keyboard.

Method 1: Using Arrays.sort() method

Output: largest number in array is: 45

Method 2:

1 Accept 10 numbers using Scanner class and store it in an array.

2 Sort the array using Arrays class.

3 Once it is sorted, we know that the last number is the largest number.

Code:

Output:

 

Method 3:

1. Accept 10 numbers using Scanner class and store it in an array.

2. Assume that the first element in an array is the max number and store it in an variable called ‘largest’.

3. Check each and every element in an array with the variable ‘largest’ and if an element is larger, then assign that value to ‘largest’.

4. Print the variable value.

Code:

Output: 

Conclusion:

In this article you have learned how to write a java program to find largest number in an array

Recommended Posts:

Find common elements in two array lists

Find the third largest number in an array in java

SQL Quick Reference

 

Tags: java program to find largest number in an array, write a java program to find largest number in an array

Images:

java program to find largest number in an array

 

Leave a Reply

Your email address will not be published. Required fields are marked *