Largest Among Three Numbers in Java

Steps:-

  • 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.in);
            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)) {
                System.out.println(a);}
            else if(b>=a && b>=c ) {
                System.out.println(b);}
            else {
                System.out.println(c);
            }}}
Largest among three numbers

Similar Java Tutorials

Leave a Comment