by Dinesh Thakur Category: Data Type

In the Following example LargestandSmallestnumber shows how to Find Largest and Smallest Number in an Array Using Java Example


Here is the java Example for the program LargestandSmallestnumber : 

public class LargestandSmallestnumber

{
       public static void main(String[] args)
      {
      //array of 15 numbers
      int no[] = new int[]{42,48,33,44,32,75,83,28,53,13,88,99,33,44,55};
     //assign the value to first element of an array to largest and smallest
     int small = no[0];
     int large = no[0];
     for(int i=1; i< no.length; i++)
        {
         if(no[i] > large)
           large = no[i];
           else if (no[i] < small)
           small = no[i];
        }
System.out.println("The Largest number is : " + large);
System.out.println("The Smallest number is : " + small);
    }
}

Find Largest and Smallest Number in an Array Using Java Example



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.