Topic: 帮忙分析一下

  Print this page

1.帮忙分析一下 Copy to clipboard
Posted by: lzx17
Posted on: 2006-05-31 15:52

What results from attempting to compile and run the following code?

public class Ternary

{

public static void main(String args[])

{

int a = 5;

System.out.println("Value is - " + ((a < 5) ? 9.9 : 9));

}

}

Choices:

a. prints: Value is - 9

b. prints: Value is - 5

c. Compilation error

d. None of these

currect choose: d

2.Re:帮忙分析一下 [Re: lzx17] Copy to clipboard
Posted by: tomcatexpert
Posted on: 2006-06-01 16:15

The integer "9" is implicitly converted to a floating-point (double) number before the operation takes place since 9.9 is floating-point number.

the correct printout will be
Value is - 9.0


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923