Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. This program determines the largest of two numbers using a simple if-else statement. The user provides two numbers as input, and the program outputs the larger number.

    import java.util.Scanner;

    public class LargestNumber {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    // Input two numbers
    System.out.print("Enter the first number: ");
    int num1 = scanner.nextInt();
    System.out.print("Enter the second number: ");
    int num2 = scanner.nextInt();

    // Determine and print the largest number
    if (num1 > num2) {
    System.out.println("The largest number is: " + num1);
    } else {
    System.out.println("The largest number is: " + num2);
    }
    }
    }
    Copied!

    Example Input/Output:

    • Input: Enter the first number: 12 Enter the second number: 15

    • Output: The largest number is: 15

    Key Considerations:

    • This program uses an if-else construct for comparison, which is straightforward and efficient for small inputs.

    • For more concise code, you can use a ternary operator or Java's built-in Math.max() function.

    Feedback
  2. Java Program to Find largest of Two Numbers - Tutorial Gateway

    This program returns the largest number among two numbers using Ternary Operator ANALYSIS 1. First, If condition checks whether number1 is equal to number2 or not if T…
    Java Program to Find Largest of Two Numbers Using Else If

    This Java program allows the user to enter two different values. Next, this Java program finds the largest number among those two numbers using Else If Statement ANALYSIS 1. The first Javaif condition checks whether number1 is greater than n…

  3. Program to find the largest of two numbers in Java

    Learn how to write a Java program to find the largest of two numbers. Step-by-step guide with code examples for beginners and Java enthusiasts.

  4. Java Program to Find Greatest of Two Numbers

    Given two integer input Number1 and Number2, the objective is to write a Java code to compare both the Numbers and Find the Greatest of the Two Numbers. …

  5. java - Find the two largest numbers - Stack Overflow

    Dec 19, 2023 · Your code doesn't handle those first two special cases, except by assuming they're bigger than zero. It also doesn't handle shunting the previously largest down to the second largest pile in the …

    • Reviews: 8
    • Java Program To Find the Largest Two Numbers in A given array

      Mar 5, 2021 · The below program demonstrates how to find the two largest numbers in an array without using Functions. In this program, firstly we declare and initialize the array.

    • Write a Java program to find the largest of two numbers. - Filo

      Jun 21, 2025 · To find the largest of two numbers in Java, we take input of two numbers from the user, then compare them using an if-else condition. If the first number is greater than the second, we print …

    • People also ask
    • Find Maximum among two numbers in Java - Interview …

      Mar 21, 2024 · This Java program demonstrates the usage of the Math.max() method to find the maximum value between two numbers. It defines two …

    • Java Program to find Largest of Two Numbers - YouTube

      In this video, you will learn how to find the largest of two numbers using a simple if-else statement in Java. We are using fixed values for variables a and b — no user input is required.

    • Java Program to Find Largest of Two Numbers

      Java Program to Find Largest of Two Numbers - This article is created to cover some programs in Java that is used to find and print the largest or biggest between two given numbers.

    • Creating a method to determine the larger of two numbers

      In this Assignment I have to write a Java program using command line arguments. There is one method required: getMax, which takes two integer variables as input and returns the bigger one of the two.