CrazyEngineers
  • execution of conditional operator

    radha gogia

    Member

    Updated: Oct 25, 2024
    Views: 1.4K
    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,...
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Sanyam Khurana

    MemberOct 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! 😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register