Java program to find the largest of three numbers

Ans: 

In this tutorial you will learn how to write a program in C to find largest of three numbers.

 

Read This: C program to find greatest among three.

How this java program will behave?

Suppose if someone give 3 numbers as input 12, 15 and 10 then our program should return 15 as a output because 15 is a greatest among three.

Java program to find greatest of three numbers

import java.util.*;  
class Main{
    public static void main(String ...args){
        Scanner sc= new Scanner(System.in);
        System.out.print("Enter first number- ");  
        int a= sc.nextInt();  
        System.out.print("Enter second number- ");  
        int b= sc.nextInt();  
        System.out.print("Enter third number- ");  
        int c= sc.nextInt();  
        if(a>=b && a>=c)
    		System.out.println(" a is greatest");
    	if(b>=a && b>=c)
    		System.out.println(" b is greatest");
    	if(c>=a && c>=b)
    		System.out.println("c is gretest");
    }
} 

Output:

java program to find greatest number among three