Largest of three numbers in java

Hey guys!!! Welcome to flower brackets blog. Today you will learn largest of three numbers in java.

largest of three numbers in java

To find largest of three numbers, comparison operator (>) is used. Comparison operator compares two numbers.

Also read Рfind largest of three using ternary operator

import java.util.Scanner;

public class LargestOfThreeDemo
{ 
   public static void main(String[] args) 
   {
      int a, b, c;
      System.out.println("Please enter three integers : ");
      Scanner sc = new Scanner(System.in);
      a = sc.nextInt();
      b = sc.nextInt();
      c = sc.nextInt();

      if(a > b && a > c)
      {
         System.out.println("first number is largest");
      }
      else if(b > a && b > c)
      {
         System.out.println("second number is largest");
      }
      else if(c > a && c > b)
      {
         System.out.println("third number is largest");
      }
      else
      {
         System.out.println("numbers are not distinct");
      }
      sc.close();
   }
}

Output:

Please enter three integers :
26
15
65
third number is largest


Also read – find largest of three using nested if

Related Posts