How does  "return newBit == false ? 0 : 1;" works in java programming?

1 Answer

  • EddieJ
    Lv 7
    5 months ago
    Favorite Answer

    It's a shorter way of saying:

    if (newBit == false) return 0; else return 1;

    However, there is a shorter way

    return newBit ? 1 : 0;

    Assuming newBit is a boolean, you don't have to compare it to true or false.

    https://www.tutorialspoint.c/ o m/Java-Ternary-Operator-Examples

Still have questions? Get your answers by asking now.