Write a Program to Find Largest and Smallest Number in an Array


The below program demonstrates largest and smallest Number in an Array.

public class FindMaxAndSmallNumber {

    /**
     * @param args
     */
    public static void main(String[] args) {
       
         int numArr[] = {91,16,4,99,33,153,48,29,68,85,100,105};
         int smallest = numArr[0];
         int biggest = numArr[0];
         for(int i=1; i< numArr.length; i++)
         {
         if(numArr[i] > biggest)
         biggest = numArr[i];
         else if (numArr[i] < smallest)
         smallest = numArr[i];
         }
         System.out.println("Largest Number is : " + biggest);
         System.out.println("Smallest Number is : " + smallest);
       
         }
}


Output: 
Largest Number is : 153
Smallest Number is : 4


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email