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

Sharad Jaiswal
Sharad Jaiswal

Posted On: Jan 04, 2019


    1 Answer Written

  •  Sharad Jaiswal
    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);
                System.out.println("Greatest number is:"+z);


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

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...

Ask a Question