Tuesday, 3 November 2015

Java Tutorial : Java Ternary Operator


Click here to watch in Youtube :
https://www.youtube.com/watch?v=nc-mcdLEClw&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Ternary Operator
TernaryOperatorDemo.java
class TernaryOperatorDemo
{
    public static void main(String[] args)
    {
        int value1 = 10;
        int value2 = 20;
        int result;

        boolean flag = true;

        /*
         * If flag is true, assign the value of value1 to result.
         * Otherwise, assign the value of value2 to result.
         */

        result = flag ? value1 : value2;

        System.out.println("flag is true  : " + result);

        flag = false;

        /*
         * If flag is true, assign the value of value1 to result.
         * Otherwise, assign the value of value2 to result.
         */

        result = flag ? value1 : value2;

        System.out.println("flag is false : " + result);
    }

}
Output
flag is true  : 10
flag is false : 20
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/OperatorsDemoTernaryApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OperatorsDemoTernaryApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/445777649bb0659322badeabdb5f7ba017537917/BasicJava/OperatorsDemoTernaryApp/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge