KnowledgeBoat Logo
|

Computer Applications

Write a program to accept a set of 50 integers. Find and print the greatest and the smallest numbers by using scanner class method.

Java

Input in Java

19 Likes

Answer

import java.util.Scanner;

public class KboatSmallLargeNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter 50 integers:");
        int small = Integer.MAX_VALUE, big = Integer.MIN_VALUE;
        for (int i = 1; i <= 50; i++) {
            int n = in.nextInt();
            if (n > big)
                big = n;
                
            if (n < small)
                small = n;
        }
        System.out.println("Smallest Number = " + small);
        System.out.println("Largest Number = " + big);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to accept a set of 50 integers. Find and print the greatest and the smallest numbers by using scanner class method.BlueJ output of Write a program to accept a set of 50 integers. Find and print the greatest and the smallest numbers by using scanner class method.

Answered By

8 Likes


Related Questions