Write a program in Java to find maximum and minimum of n numbers without using arrays.

 

AIM: Write a program in Java to find maximum and minimum of n numbers without using arrays.

 

CODE:

import java.util.Scanner;

public class large {

            public static void main(String[] args)

            {

                        System.out.println("l");

                        System.out.println("enter value of N: ");

                        Scanner readme = new Scanner(System.in);

                        int n = readme.nextInt();

                        int largest = Integer.MIN_VALUE;

                        int smallest = Integer.MAX_VALUE;

                        System.out.printf("enter %d numbers:", n);

                        for (int i = 0; i < n; i++)

                        {

                                    int current = readme.nextInt();

                                    if (current > largest)

                                    {

                                                largest = current;

                                    }

                                    if (current < smallest)

                                    {

                                                smallest = current;

                                    }

                        }

            System.out.println("largest is : " + largest);

            System.out.println("smallest is : " + smallest);

            }

 }

 

 

OUTPUT:



Comments

Popular posts from this blog

Write an application that illustrates method overriding in the same package and different packages. Also demonstrate accessibility rules in inside and outside packages

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a Java Program with class Rectangle having instance variable width, length, area and colour. Create methods like setData() and area().Create two object of Rectangle and compare their area and colour. If area and colour both are the same for the objects then display “Matching Rectangles”, otherwise display “Non matching Rectangle”.