This Java program reads input from the user and finds the largest and smallest numbers among them. It repeatedly prompts the user to enter a number and asks if they want to continue. It keeps track of the largest and smallest numbers using the variables max and min, which are initially set to the minimum and maximum possible integer values, respectively.
Here is a step-by-step explanation of how the program works:
import java.util.Scanner; class Display_Largest_Smallest{ public static void main(String[] args) { Scanner input = 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 = input.nextInt(); if(number > max) { max = number; } if(number < min) { min = number; } System.out.print("Do you want to Continue y/n ? :"); choice = input.next().charAt(0); }while(choice=='y' || choice == 'Y'); System.out.println("Largest Number : " + max); System.out.println("Smallest Number : " + min); } }
Enter the Number :34 Do you want to Continue y/n ? :y Enter the Number :78 Do you want to Continue y/n ? :y Enter the Number :12 Do you want to Continue y/n ? :n Largest Number : 78 Smallest Number : 12
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions