Write a Java-program to print max number using if else condtion

Write a Java-program to print max number using if else condtion

Program
public class Main
{
	public static void main(String args[])
	{
        int x=10,y=20;
        if(x>y)
        {
            System.out.println("x is Max Number");
        }
        else
        {
            System.out.println("y is Max Number");
        }
	}
}	

Output:

y is Max Number

Using CommandLine Arguments
public class Main
{
	public static void main(String args[])
	{
        int x,y;
        x=Integer.parseInt(args[0]);
        y=Integer.parseInt(args[0]);
        if(x>y)
        {
            System.out.println("x is Max Number");
        }
        else
        {
            System.out.println("y is Max Number");
        }
	}
}	

Output:

y is Max Number

Using Scanner Class
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
        int x,y;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter x ,y values");
        x=s.nextInt();
        y=s.nextInt();
        if(x>y)
        {
            System.out.println("x is Max Number");
        }
        else
        {
            System.out.println("y is Max Number");
        }
	}
}	

Output:

Enter x values
10
20
y is Max Number





More Questions


25 . Write a Java-program to print max number using if else condtion
26 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3)
27 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4)
28 . Write a Java-program to check the given number is valid or invalid(value must divisible by 2 and 3 not 4 using 2 conditions)
29 . Write a Java-program to check the given number is valid or invalid(value must between 20 and 30)
30 . Write a Java-program to check the given character is vowel or consonant
31 . Write a Java-program to check the given character is small letter or not
32 . Write a Java-program to check the given character is capital letter or not
33 . Write a Java-program to check the given character is number or not
34 . Write a Java-program to check the given character is symbol letter or not
35 . Write a Java-program to calculate simple interest with following condtions