参见英文答案 >
Why does the ternary operator unexpectedly cast integers?2
我无法理解下面的代码如何打印50.0
我无法理解下面的代码如何打印50.0
public class Pre { public static void main(String[] args) { int x=10; System.out.println((x > 10) ? 50.0 : 50); //output 50.0 } }
它应该打印50(我猜)不是50.0
public class Pre { public static void main(String[] args) { int x=10; if(x>10) System.out.println(50.0); else System.out.println(50);//output } }
如果他们是等价的,那么为什么产出差异?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。