Tech Study

Java Program To Find The Largest And Smallest Numbers Entered

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.Scanner;
 
public class JavaLoopExcercise
{
    public static void main(String[] args)
    {
        Scanner console = new Scanner(System.in);
 
        int number;
        int max = Integer.MIN_VALUE;  
        int min = Integer.MAX_VALUE;  
 
        char choice;
 
        do
        {
            System.out.print("Enter the number ");
            number = console.nextInt();
 
            if(number > max)
            {
                max = number;
            }
 
            if(number < min)
            {
                min = number;
            }
 
            System.out.print("Do you want to continue y/n? ");
            choice = console.next().charAt(0);
 
        }while(choice=='y' || choice == 'Y');
 
        System.out.println("Largest number: " + max);
        System.out.println("Smallest number: " + min);
    }  
}

Result

Write a Java program to enter the numbers till the user wants and at the end the program should display the largest and smallest numbers entered
Write a Java program to enter the numbers till the user wants and at the end the program should display the largest and smallest numbers entered

Java Program to Calculate & Print Average of 5 Numbers

Write a Java program to print the odd numbers from 1 to 20

TaggedWrite a Java program to enter the numbers till the user wants and at the end the program should display the largest and smallest numbers entered

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more