Why can't I use the ternary ? operator to select between two function calls?

后端 未结 4 1370
悲哀的现实
悲哀的现实 2020-12-03 23:24

I was recently programming and ran into an issue using the ? : operand. Here\'s my code.

    Random rand = new Random();
    for(int x = 0; x < 3; x++) {
         


        
4条回答
  •  天涯浪人
    2020-12-03 23:50

    The compiler is right. The ternary operator returns something, so you need to assign it to a variable.

提交回复
热议问题