Enter two user defined numbers and find maximum of 2 numbers using if else statement in java

Write a java program to enter two user-defined numbers and find maximum of 2 numbers using if-else statement.

import java.util.*;
public class max1 
{
     public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int a,b;
        System.out.println("enter a");
        a=s.nextInt();
        System.out.println("enter b");
        b=s.nextInt();
        System.out.println("a is:"+a);
        System.out.println("b is:"+b);
        if(a>b)
        {
            System.out.println("a is max");
        }
        else
        {
            System.out.println("b is max");
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *