9 Find greatest of three number using Ternary Operator in Java.

Ternary.java

class Ternary
{
public static void main( String args[] )
{
int a = Integer.parseInt( args[0] );
int b = Integer.parseInt( args[1] );
int c = Integer.parseInt( args[2] );

int max;

max = (a>b) ? a : b;
max = (max>c) ? max : c;

System.out.println("\n\n Greatest Number= "+max);

  }
}




Output:  

Previous
Next Post »