编译运行以下程序后,关于输出结果的说明正确的是 ( )

public class Conditional{
  public static void main(String args[ ]){
      int x=4;
      System.out.println("value is "+ ((x>4) ? 99.9 :9));
  }
}
A. 输出结果为:value is 99.99
B. 输出结果为:value is 9
C. 输出结果为:value is 9.0
D. 编译错误

参考解答

C (x>4) ? 99.9 :9)表达式中含有99.9是double类型,所以整个表达式的结果也是double类型,输出结果为 value is 9.0


results matching ""

    No results matching ""