java program to find largest number in an array

By | October 20, 2019

In this article, we are going to learn how to find the maximum number from the input elements from the keyboard.

Method 1:

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 2:

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: 

 

Other reads:

Find common elements in two array lists

SQL Quick Reference

Leave a Reply

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