Home Java Programming Language / Programs / Write a program to input integer elements into an array of size 20 and perform the following operations: Display largest number from the array. Display smallest number from the array. Display sum of all the elements of the array
🚀 Programming Example

Write a program to input integer elements into an array of size 20 and perform the following operations:

  1. Display largest number from the array.
  2. Display smallest number from the array.
  3. Display sum of all the elements of the array

👁 134 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Given Input:


Expected Output:


💻 Program Code

import java.util.Scanner;

public class RAnsariSDAMinMaxSum
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int arr[] = new int[20];
        System.out.println("Enter 20 numbers:");
        for (int i = 0; i < 20; i++) {
            arr[i] = in.nextInt();
        }
        int min = arr[0], max = arr[0], sum = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < min)
                min = arr[i];

            if (arr[i] > max)
                max = arr[i];

            sum += arr[i];
        }

        System.out.println("Largest Number = " + max);
        System.out.println("Smallest Number = " + min);
        System.out.println("Sum = " + sum);
    }
}
                        

🖥 Program Output

Enter 20 numbers:
12 43 56 45 6 3 4 5 12 44 23 23 45 22 11 23 45 78 99 76 33
Largest Number = 99
Smallest Number = 3
Sum = 675
Press any key to continue . . .


                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.