execution of conditional operator

radha gogia

radha gogia

@radha-BTDzli Oct 25, 2024
I just wanted to know how actually the expression which has many conditional operators in it is executed..

e.g System.out.println(8>2?7<3?6>3?5:3:9:1);

I just wanted to know that here I have 2 conditions to be true ,so corresponding to it ,actually how the output would be generated,...

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Sanyam Khurana

    Sanyam Khurana

    @sanyam-Nl7Zqc Oct 12, 2014

    I think, it would be just like in case of nested if else statement. This would work as:
    System.out.println(8>2?7<3?6>3?5:3:9:1);
    => System.out.println(8>2?7<3?5:9:1);
    => System.out.println(8>2?9:1);
    => System.out.println(9);

    So, it would print 9! 😀