Java Program to Find the Largest Among Three Numbers

In this example, we are giving a program to the find the largest number among three numbers.


To find the largest number among three numbers:

  1. # To find the largest number among three numbers
  2. public class Largest {
  3. public static void main(String[] args) {
  4. double n1 = 27.3, n2 = 15, n3 = -57.8;
  5. if ( n1 >= n2 && n1 >= n3)
  6. System.out.println(n1 + " is the largest number.");
  7. else if (n2 >= n1 && n2 >= n3)
  8. System.out.println(n2 + " is the largest number.");
  9. else
  10. System.out.println(n3 + " is the largest number.");
  11. }
  12. }

Output:

27.3 is the largest number.