Jan 24, 2022

Java Program To Find Largest Number Among Three Number - Java Program Example

Here Write A Java Program To Find Largest Number Among Three Numbers. When We Will Compile This Program On Java Compiler Then Compiler Ask Three Integer  Numbers As Input By User  For Comparison . And Show Largest, Smallest Number As Output After Compile On The Screen.


Program Code


package com.androidpro.in;

import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
import
java.io.PrintStream;
import
java.util.Scanner;

public class
Main {

   
public static void main(String args[])
    {
       
int x, y, z;
       
System.out.println("Enter three integers ");
       
Scanner in = new Scanner(System.in);

       
x = in.nextInt();
       
y = in.nextInt();
       
z = in.nextInt();

        if
( x > y && x > z )
            System.
out.println("First number is largest.");
        else if
( y > x && y > z )
            System.
out.println("Second number is largest.");
        else if
( z > x && z > y )
            System.
out.println("Third number is largest.");
        else
           
System.out.println("Entered numbers are not distinct.");
   
}

}



 Output

Enter three integers

666

989

909

Second number is largest.

 

Process finished with exit code 0

Share:

0 Comments: