Category : Java | Sub Category : Operator | By Prasad Bonam Last updated: 2020-09-28 13:41:33 Viewed : 793
/**
* Write a program which
demonstrates the Ternary (?) operator.
*/
public class
Ternary { // Declare class name
public static void
main(String a[]) { // Main body of programme start from here.
int
i, k; // daclare two variables i & k.
i = 10; //
Initialize i
k = i < 0 ? -i
: i; // get absolute value of i.
System.out.print("Absolute
value of "); // print string line
System.out.println(i
+ " is " + k); //
this print the value of i and k.
i = -10; //
Initialize
k = i < 0 ? -i
: i; // get absolute value of i.
System.out.print("Absolute
value of "); // print string line
System.out.println(i
+ " is " + k); //
this show the value of i and k.
} //
Main body of programme ended
} // class ended
Absolute value of -10 is 10