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) ;
}
}
Thank u sir Afroz
ReplyDelete