Check Greater of Two Numbers

This program finds the greater of two numbers using if-else.

Problem Statement

Write a Java program that finds the greater of two numbers.

Source Code

1 public class GreaterTwo {
2 public static void main(String[] args) {
3 int a = 15, b = 20;
4 if(a > b) {
5 System.out.println("Greater number: " + a + " - Eduinq");
6 } else {
7 System.out.println("Greater number: " + b + " - Eduinq");
8 }
9 }
10 }

Program Output

Greater number: 20 - Eduinq

Explanation

The program compares a and b using an if-else statement and prints whichever value is greater. Shows comparison using if-else.

Quick Links to Explore