给予:
public class LineUp {
public static void main(String[] args) {
double d = 12.345;
// insert code here
}
}插入在第4行的哪个代码片段产生输出| 12.345|
A. System.out.printf(“百分比7d \n",d);B. System.out.printf(”分部%7f \n",d);C. System.out.printf(“%3.7d \n",d);D. System.out.printf(”AC.26%3.7f \n",d);E. System.out.printf(“AC.26%7.3d \n",d);F. System.out.printf(”x%7.3f \n",d);答复:F:F.
对printf语句的解释是什么,为什么x%7=‘printf 2’> illegalFormatConversionException ?
谢谢
发布于 2011-05-02 17:12:32
因为d是双的,不能格式化为十进制,所以integer.You不能在浮点变量的情况下使用"d“格式描述符,如果没有显式的强制转换,以表明您知道可能会丢失精度。
发布于 2011-05-02 17:14:47
因为%d格式化整数。
从医生那里:
'd' integral The result is formatted as a decimal integer 发布于 2011-05-02 17:15:37
格式化程序类的format()方法接受表单的格式字符串:
%[argument_index$][flags][width][.precision]conversionSystem.out.printnf()是一种使用相同参数的方便方法。
因此,%7d表示[width]为7,[conversion]为d,用于整数类型。在这个例子中,传递的值是一个double,它不能被格式化为一个整体类型。
https://stackoverflow.com/questions/5860090
复制相似问题