標題:
printf() 函式 (一)
[打印本頁]
作者:
tonyh
時間:
2020-11-13 19:34
標題:
printf() 函式 (一)
本帖最後由 tonyh 於 2020-11-13 20:04 編輯
假設本練習中的四個變數分別為
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
試利用printf()函式完成如下之執行畫面:
public class Ch100 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.1f%n",c); //四捨五入至小數點後1位
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b); //指定總長度為9個字元
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d); //指定總長度為9個字元,不足的部分以0補上
}
}
複製代碼
作者:
夏子涵
時間:
2020-11-13 20:05
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.3f%n",a);
System.out.printf("%.2f%n",b);
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
李宇澤
時間:
2020-11-13 20:07
public class Ch15 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.3f%n",a);
System.out.printf("%.2f%n",b);
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
黃宥華
時間:
2020-11-13 20:07
本帖最後由 黃宥華 於 2020-11-13 20:21 編輯
public class Ch999 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
黃柏叡
時間:
2020-11-13 20:07
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.3f%n",a);
System.out.printf("%.2f%n",b);
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
董宸佑
時間:
2020-11-13 20:08
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.1f%n", c);
System.out.printf("%.0f%n", d);
System.out.printf("%9.2f%n", a);
System.out.printf("%9.2f%n", b);
System.out.printf("%09.2f%n", c);
System.out.printf("%09.2f%n", d);
}
}
複製代碼
作者:
孫嘉駿
時間:
2020-11-13 20:08
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
蔡忻霓
時間:
2020-11-13 20:08
public class Ch64 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.3f%n",a);
System.out.printf("%.2f%n",b);
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
林政瑜
時間:
2020-11-13 20:09
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.3f%n",a);
System.out.printf("%.2f%n",b);
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
沈子晏
時間:
2020-11-13 20:09
本帖最後由 沈子晏 於 2020-11-13 20:10 編輯
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.3f%n",a);
System.out.printf("%.2f%n",b);
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%9.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
劉愷鈞
時間:
2020-11-13 20:10
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.1f%n",c);
System.out.printf("%.0f%n",d);
System.out.printf("%8.2f%n",a);
System.out.printf("%8.2f%n",b);
System.out.printf("%09.2f%n",c);
System.out.printf("%09.2f%n",d);
}
}
複製代碼
作者:
陳宥穎
時間:
2020-11-13 20:10
public class Ch01 {
public static void main(String[] args) {
double a=3.456789;
double b=34.56789;
double c=345.6789;
double d=3456.789;
System.out.printf("%.1f\n",c);
System.out.printf("%.0f\n",d);
System.out.printf("%9.2f\n",a);
System.out.printf("%9.2f\n",b);
System.out.printf("%09.2f\n",c);
System.out.printf("%09.2f\n",d);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2