Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个java代码:
重量=重量== 0?1:重量;
谁能解释在所有情况下可变重量会发生什么?
如果 weight 等于 0,则 weight 将设置为 1,否则保持不变。
很多人不喜欢三元?运算符,因为它更难阅读。那些人会写
if (weight == 0) { weight = 1; }
他们有一个观点,我会说。