標題:
[作業] printf() 函式 (一)
[打印本頁]
作者:
tonyh
時間:
2021-12-25 20:21
標題:
[作業] printf() 函式 (一)
本帖最後由 tonyh 於 2021-12-25 20:59 編輯
假設本練習中的四個變數分別為
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補上
}
}
複製代碼
作者:
余柏緯
時間:
2022-1-8 16:23
public class Ch60 {
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);
}
}
複製代碼
作者:
林鼎傑
時間:
2022-1-8 19:32
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);
}
}
複製代碼
作者:
朱奕祐
時間:
2022-1-8 19:33
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);
}
}
複製代碼
作者:
蔡寓珉
時間:
2022-1-8 19:34
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);
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);
}
}
複製代碼
作者:
林佑宸
時間:
2022-1-8 19:35
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);
}
}
複製代碼
作者:
呂尚霖
時間:
2022-1-8 19:38
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);
}
}
複製代碼
作者:
黃子倢
時間:
2022-1-8 19:38
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);
}
}
複製代碼
作者:
俞成章
時間:
2022-1-8 19:39
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);
}
}
複製代碼
作者:
王秉鈞
時間:
2022-1-8 19:40
public class Ch26 {
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("%0.1f%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);
}
}
複製代碼
作者:
林土水
時間:
2022-1-8 19:41
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);
}
}
複製代碼
作者:
許洧熏
時間:
2022-1-8 19:43
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);
}
}
複製代碼
作者:
陳志祐
時間:
2022-1-15 01:05
public class Ch70 {
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