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(;
      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");
         System.out.println("numbers are not distinct");


Please enter three integers :
third number is largest

Also read – find largest of three using nested if

Related Posts