Write a Program to Find largest and smallest number in an array in java

Write a Program to Find largest and smallest number in an array in java

Write a Program to Find largest and smallest number in an array in java

Program
public class Main 
{
public static void main(String[] args) 
    {
        int a[] = new int[] { 23, 34, 13, 64, 72, 90, 10, 15, 9, 27 };
        int min = a[0];// assume first elements as smallest number 
        int max = a[0]; // assume first elements as largest number 
        for (int i = 1; i < a.length; i++) // iterate for loop from arrays 1st index (second element) 
        { 
            if (a[i] > max)
            { 
                max = a[i];
            } 
            if (a[i] < min) 
            {
                min = a[i]; 
            }
        }
        System.out.println("Largest Number in a given array is : " + max); 
        System.out.println("Smallest Number in a given array is : " + min);
    }
}


Output:

Largest Number in a given array is : 90
Smallest Number in a given array is : 9



More Questions


39 . Write a Program to find second largest number in an array
40 . Write a Program to Find largest and smallest number in an array in java
41 . Write a Java Program to find largest and second largest in an array
42 . Write a java program to find the index of the largest number in an array
43 . Write a java program to Find the index of the smallest number in an array
44 . Write a Program to remove duplicate element in an array
45 . Write a java Program to print odd and even numbers from an array
46 . Write a java program to add two matrix
47 . Write a java Program to check given matrix is null matrix
48 . Add all the digits of a given positive integer until the result has a single digit
49 . Write a Java program to accept a float value of number and return a rounded float value



For latest job updates join Telegram Channel: https://t.me/sateeshm

Apply For The Job

Apply For Job

Java Material

Python Material

PLSQL Material

.Net Material

Java Practice Programs

400 Java Programs