Largest of three numbers java program

Overview

Here is a java program to find the largest of the three numbers.  In this example the user will input three numbers and the program will output the largest number

Largest of three numbers Example


package com.programtalk.learn.java.largest3numbers;
import java.util.Scanner;
 
class HighestNumberThreeNumbers
{
   public static void main(String args[])
   {
      
      Scanner in = new Scanner(System.in);
      System.out.println("Enter First Integer");      
      int firstNumber = in.nextInt();
      System.out.println("Enter Second Integer");
      int secondNumber = in.nextInt();
      System.out.println("Enter Third Integer");
      int thirdNumber = in.nextInt();
      in.close();
      System.out.println("Working...");
      int highestNumber = firstNumber;
      if(highestNumber < secondNumber){
    	  highestNumber = secondNumber;
      }
      if(highestNumber < thirdNumber){
    	  highestNumber = thirdNumber;
      }
      System.out.println("Highest Number is:" + highestNumber);
   }
}

output:

Enter First Integer
21
Enter Second Integer
23
Enter Third Integer
56
Working...
Highest Number is:56
Like this post? Don’t forget to share it!