Which of the following data types will allow the following code snippet to compile?



float i = 4;
float j = 2;
ˍˍˍˍˍ z = i + j;

Which of the following data types will allow the following code snippet to compile?

A. long
B. double
C. int
D. float
E. byte

題解

單精準浮點數(float)為32位元的浮點數,雙精準浮點數(double)為64位元的浮點數。由於i變數和j變數都是32位元的單精準浮點數,因此它們的運算結果也為32位元的單精準浮點數,也可以使用64位元的雙精準浮點數型態來儲存。所以z變數可以使用的資料型態為float和double。