Write a Java-program to print max number using ternary operator

Write a Java-program to print max number using ternary operator

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

Output:

y is Max

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

Output:

y is Max

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

Output:

Enter x, y values
10
20
y is Max





More Questions


22 . Write a Java-program to print max number using ternary operator
23 . Write a Java-program to print MAX Number Amoung 3 Numbers
24 . Write a Java-program to print ODD or Even Number using if else condition
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