Java program for largest of three numbers

Program Description

Write a java program to find the largest of three numbers. In the program we will prompt user to enter three numbers. Using if-else if clauses, we will decide the largest number out of the three numbers.  

Java Program

import java.util.Scanner; 

/**************************************************
 * LargestOfThreeNumbers.java
 * @program   	: LargestOfThreeNumbers Java Program. 
 * @web        	: www.TestingDocs.com
 * @version     : 1.0
 **************************************************/

public class LargestOfThreeNumbers {
  public static void main(String[] args) {
    int a, b, c; 
    Scanner sc = new Scanner(System.in); 
    System.out.print("Please enter a :=");
    a = sc.nextInt(); 
    System.out.print("Please enter b :=");
    b = sc.nextInt(); 
    System.out.print("Please enter c :=");
    c = sc.nextInt(); 
    if(a > b && a > c) {
      System.out.println("a i.e ("+ a + ") is the largest number."); 
    } else if(b > a && b > c) { 
      System.out.println("b i.e ("+ b + ") is the largest number."); 
    } else if(c > a && c > b) { 
      System.out.println("c i.e (" + c + ") is the largest number.");
    } else {
      System.out.println("Given three numbers are not distinct");
    } 
    sc.close(); 
  } 
}

 

Program Output

Please enter a :=15
Please enter b :=6
Please enter c :=22
c i.e (22) is the largest number.

Screenshot

Largest of Three Numbers Java program