Comparing Two Numbers In JAVA

In JAVA Programming , We can Provide you simple example of Java that teaches you the method of comparing two numbers and finding out the greater one.


First, name a class “Compare” and Then we have taken this two Number   i=45 and j=50,


now we have to find out whether  i=j, i>j or j>i .


To find out then this apply if and else condition one by one.


Now apply the condition “if (i=j)”, if this satisfies then type that both are equal in the system class.


If this doesn’t satisfy, then check whether i>j by applying the “else if” condition and type the message “i is greater than j” in the system class.


Now This condition check one by one and you have to write result or print result on System.Out.Println.

class  Compare {
public static void main(String[] args) {
int i = 45, j = 50;
if (i == j){
System.out.println(“i and j are equal”);
else if(i>j){
System.out.println(“i is greater than j”);
System.out.println(“j is greater than i”);

Enjoy Coding.