Java Program to Check Whether a Number is Even or                                                        Odd

Find the Greatest of the two numbers in Java

Given two integer inputs num1 and num2, the objective if to write a code to Find the Greatest of the     

Two Numbers in Java.

Example

Input : num1 = 5 and num2 = 6

Output : 6

Flow Diagram:-

Greatest of two numbers.png

Code:-

  • If num1 == num2

  •        Print both are equal

  • Else if num1 > num2

  •       Print num1 is greater

  • Else, num2 has to be the greater

  •       Print num2 is greater

Algorithm:-

Code:-

public class Main
{
   public static void main (String[]args)
   {

     int num1 = 22, num2 = 10;
     if (num1 == num2)
       System.out.println ("both are equal");
     else if (num1 > num2)
         System.out.println (num1 + " is greater");

     else
         System.out.println (num2 + " is greater");

   }
}

Output:-

Enter a number: 22 10

22 is greater