Java Program To Find Smallest and Largest  Number in an Array

Find Largest and Smallest Number in an Array means how to find the largest and smallest numbers in an array. In this example, we use 10 numbers in which we find the smallest and largest value.

Program to Find Smallest and Largest in Java Array

public class FindLargeSmall

 {

public static void main(String[] args)

{

//array of 10 numbers

          int numbs[] = new int[]{32,43,53,54,32,65,63,98,43,23}; 

          //assign the first element of an array to the largest and smallest

          int smallestno = numbs[0];                         

//assign the first element of an array to the smallest

          int largetstno = numbs[0];                            

//assign the first element of an array to the largest

            //for loop is used to find the largest and smallest from start to end digit

              for(int i=1; i< numbs.length; i++)  

                {

                if(numbs[i] > largetstno)                     //condition check if true then

                largetstno = numbs[i];                        //assign the value to largestst

               else if (numbs[i] < smallestno)   

                smallestno = numbs[i];

                 }

                 System.out.println(“Largest Number is : ” + largetstno);

                System.out.println(“Smallest Number is : ” + smallestno);

                }

                }

Find the Smallest and Largest number in the array of Java

                Explanation ….

In the above program, we use an array for finding the smallest and largest number. We enter 10 numbers in an array and by using for loop we can find the result. Searching always starts with zero. The index of the elements in an array always starts with 0.