Topics Index

Find maximum number in array

If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to find the maximum number in array.

Input (Integer Array) Output (Integer)
{2, 3, 4, 7, 6, 1} 7
{3, 9, 1, 5, 16, 10} 16
{195, 31876, 123, 20000, 15122, 789} 31876
{36187, 31876, 38761, 37861, 37618, 38671} 38761

class MaximumNumberInArray
    public static void main(String s[])
        int[] input = {2, 3, 8, 5, 4};
        int maximum = getMaximumNumberInArray(input);
        System.out.println("Maximum Number is " + maximum);


    public static int getMaximumNumberInArray(int[] array)
        int result = 0;
        return result;

Topic: Learn Arrays And Loops

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

After Execution start it will enter into main() method the array of input variable initialized with the values 2,3,8,5,4.....  after the execution of next statement it will enter into getMaximumNumberInArray() method with input array object as a parameter..... Inside the method the variable "result" initialized with the values of array[0]  then it will become result=2, and take one for-loop with the size from i=1 to i<array.length(),and i++  inside loop take if condition with if(array[i]>result) and with one statement inside if-condition as result=array[i] and then close the for-loop... after that we are returning the value of result then compiler will go to main() method and then it will print the maximum 8

Posted by Bhagi Bhagyasri    2015-01-19 06:01:08

for finding largest Number of Array... i suggest a simple algorithm as follows...
1)largest = the first item
2)for all the items except the first
       3)if the current item is larger than largest
                   4)replace the value in largest with the current item

5)copy largest value to result

Posted by ?????????? ?????    2015-01-19 06:52:20

here we need to compare the each element if some element is big than swap the index of that num..finally we will have the index of the big element..

*take big=0;
*start loop to travel through the array till the end

* compare the array element with big
* if the element in the Array is big than store the index of that element in the big

* after coming out of the loop return the element at index big

Posted by Uday Kumar    2015-01-19 11:50:53

To Find the Maximum No from Array of integers we find the large no from 1st two then larger of two is compared with 3rd.

-same process is continued till the last element of array is reached.

Following steps must be followed to find maximum no from array :

1)First Element is assigned to large.

--> large=a[0]

2)One Loop is used which runs till the length of the array minus 1.

---> for(int i=1;i<a.length-1;i++)

3)Here,"TERNARY OPERATOR" is used to find the larger of two numbers.

---> large=(large>a[i])?large:a[i];

4)At the end of loop,We display the large number using system.out.print().

Posted by Mânïshå Mùlchåndânï    2015-01-20 17:23:43

This dose is now closed and the winners are Bhagi Bhagyasri,  for 'First Correct Comment', ?????????? ?????, Uday Kumar, Mânïshå Mùlchåndânï,  for 'Second Correct Comment'. The 'lucky liker' is Ananthoju Arun Chary. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-01-21 07:04:03

© meritcampus 2019

All Rights Reserved.

Open In App