標題:
printf() 函式 (一)
[打印本頁]
作者:
may
時間:
2023-3-6 17:39
標題:
printf() 函式 (一)
假設本練習中的四個變數分別為
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補上
}
}
複製代碼
作者:
鍾易澄
時間:
2023-3-11 11:27
public class Dfgh {
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);
}
}
複製代碼
作者:
許宸瑀
時間:
2023-3-11 11: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);
}
}
複製代碼
作者:
高鋐鈞
時間:
2023-3-11 11: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);
}
}
複製代碼
作者:
柳侑辰
時間:
2023-3-11 11:32
public class Ch02
{
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",c);
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);
}
}
複製代碼
作者:
田家齊
時間:
2023-3-11 11:34
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);
}
}
複製代碼
作者:
曾善勤
時間:
2023-3-11 11: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);
}
}
複製代碼
作者:
孫子傑
時間:
2023-3-11 12:03
public class SDAWD {
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);
}
}
複製代碼
作者:
高昀昊
時間:
2023-3-11 16:41
public class Ch04{
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);
}
}
複製代碼
作者:
利勁鋼
時間:
2023-3-12 21:53
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);
}
}
複製代碼
作者:
林紘憲
時間:
2023-3-17 22:35
public class Dfgh {
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