Showing posts with label Write a program to input three integers and print the largest and smallest integers using suitable mathematical functions.. Show all posts
Showing posts with label Write a program to input three integers and print the largest and smallest integers using suitable mathematical functions.. Show all posts

Friday, 24 April 2020

Find the Largest and Smallest integer among three integers using Java Program



Write a program to input three integers and print the largest and smallest integers using suitable mathematical functions.

import java.util.*;
class  Q8
{
    public static void main(String args[])
    {
        int v1 ,v2 ,v3 , lar , large , sm , small ; 
       
        Scanner sk = new Scanner(System.in) ;
    
        System.out.print("Enter 1st integer value :  ") ;
        v1 = sk.nextInt() ;   
        System.out.print("Enter 2nd integer value :  ") ;
        v2 = sk.nextInt() ; 
        System.out.print("Enter 3rd integer value :  ") ;
        v3 = sk.nextInt() ;
       
        //======== Mathematical Function =====================
       
        lar = Math.max(v1 , v2) ;
        large = Math.max(lar , v3) ;
       
        sm = Math.min(v1 , v2) ;
        small = Math.min(sm , v3) ;
               
        System.out.println(" Largest integer is : " +large) ;
        System.out.println(" Smallest integer is  : " +small) ;
    }
}