The following code is intended to input two integers and print the average. What is a potential problem with the code as written?  下面的代码用于输入两个整数并打印它们的平均值。 这段代码可能存在哪些问题? System.out.println("Please enter two integers: "); int a = scan.nextInt(); int b = scan.nextInt(); System.out.println("The average is: " + (a + b) / 2); 单项选择题

A

It should use scan.nextDouble instead of scan.nextInt. 它应该使用 scan.nextDouble 而不是 scan.nextInt。

B

There is no division needed. 不需要划分。

C

It needs a cast so that the decimal portion will be shown. 它需要进行转换才能显示小数部分。

D

No correction needed, the code will work as written. 无需更正,代码将按编写的方式运行。

E

The parentheses are not needed and will cause a mathematical error. 括号是不需要的,否则会导致数学错误。

登录即可查看完整答案

我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!