Write a program to find the greatest of three numbers in Java?

devquora
devquora

Posted On: Feb 22, 2018

 

    1 Answer Written

  •  devquora
    Answered by Degala Jaswanth Sai

    Simple Java Program to find the Greatest/ largest number among 3 numbers

    import java.util.Scanner;
    public class Greatest_Number 
    {
        public static void main(String[] args) 
        {
            int x, y, z;
            Scanner s = new Scanner(System.in);
            System.out.print("Enter the first number:");
            x = s.nextInt();
            System.out.print("Enter the second number:");
            y = s.nextInt();
            System.out.print("Enter the third number:");
            z = s.nextInt();
            if(x > y && x > z)
            {
                System.out.println("Greatest number is:"+x);
            }
            else if(y > z)
            {
                System.out.println("Greatest number is:"+y);
            }
            else
            {
                System.out.println("Greatest number is:"+z);
            }
     
        }
    }
    

    Output

    Enter the first number:20
    Enter the second number:37
    Enter the third number:45
    Greatest number is:45
    

Related Questions

Please Login or Register to leave a response.

Related Questions

Capgemini Java interview questions

What is database normalization? Explain types of it.

In SQL, normalization of data is a process through with data is organized in tables used for the reduction of redundancy and dependency of data. It divides large tables into smaller ones using some se...

Capgemini Java interview questions

What is difference between Class and object In JAVA?

Difference between Class and object In JAVA:Class - A class is like a blueprint. It is the class with the help of which objects are created. The class holds together data and methods in one single...