July 20, 2012

Java Ternary Example

Java Ternary Example - An alternate solution for if- else in java.


/**
 * @author ComputerScience
 *
 */
public class TerenaryExample {
    public static void main(String[] args) {
        int i = 0;
        int j = 1;
        String k = i < j ? "i less than j" : "j less than i";
        System.out.println(k);
    }
}


Thanking you....

1 comment:

Your feedback may help others !!!

Facebook comments