SCJP題庫第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
 
解說:
printfJavaJDK 1.5提供C時代超級好用的printf格式化輸出,%d是對應的輸出是10進位值(decimal)%ffloat
7.3則是整數7位小數點3位。

Comments

Popular posts from this blog

Android-使用webview在V3版的Google地圖GPS定位