In this program, we will use some inbuilt Mathematical functions in Java to find the largest value among the two numbers.
Example: Find Largest Number Among Two Numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter first number: "); int n1 = in.nextInt(); System.out.println("Enter second number: "); int n2 = in.nextInt(); int largest = Math.max(n1, n2); System.out.println("Largest among (" + n1 + ", " + n2 + ") is: " + largest); } } |
1 2 3 4 5 |
Enter first number: 12 Enter second number: 8 Largest among (12, 8) is: 12 |