Java Program:

- To find largest number between 2 numbers

Example:

User Input: 2,3

Output: 3 is largest

import java.util.Scanner;
public class FindLargest {
  public static void main(String []args) {
    int n1,n2;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter two numbers : ");
    n1 = userInput.nextInt();
    n2 = userInput.nextInt();

    if(n1>n2) System.out.print(n1);
    else System.out.print(n2);

    System.out.print("is the largest number");
  }
}

Output:

  Enter two numbers : 7
  5
  7 is the largest number
Program
basic

Here, we use 2 variables (above code n1 & n2) to take numbers from the user

Now, check for the largest number using if statement

if(n1>n2){
  // if true print n1
}
else {
  // if false print n2
}

OR

if(n1<n2){
  // if true print n2
}
else {
  // if false print n1
}
Concept

Coming Soon !

Quick
Tutorial

Quote

I believe things cannot make themselves impossible.