Largest Among Three Numbers in Java


  • Take three numbers input from the user.
  • check the first number is greater than the rest two numbers.
  • check the second number is greater than the rest two numbers.
  • else print the third number.

Java Program Largest Among Three Numbers Using if else:-

import java.util.Scanner;

public class LargestInThreeNum {

        public static void main(String[] args) {
            Scanner sc = new Scanner(;
            System.out.println("Enter first number");
            int a = sc.nextInt();
            System.out.println("Enter second number");
            int b = sc.nextInt();
            System.out.println("Enter third number");
            int c = sc.nextInt();
            System.out.print("The largest number is : ");
            if((a>=b) && (a>=c)) {
            else if(b>=a && b>=c ) {
            else {
Largest among three numbers

Similar Java Tutorials

Leave a Comment