SCJP 1.6版考題 147
出自 陳富國維基館
Given: 1. public class LineUp{ 2. public static void main(String[] args){ 3. double d = 12.345; 4. //insert code here 5. } 6. } Which code fragment, inserted at line 4, produces the output |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("|%3.7f| \n", d); E. System.out.printf("|%7.3d| \n", d); F. System.out.printf("|%7.3f| \n", d);
解答
Ans: F
解說:
printf是Java在JDK 1.5提供C時代超級好用的printf格式化輸出, %d是對應的輸出是10進位值(decimal),%f是float 7.3則是整數7位小數點3位。
|