標題:
printf() 函式 (一)
[打印本頁]
作者:
陳弘修
時間:
2021-2-20 10:07
標題:
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補上
}
}
複製代碼
作者:
林羿丞
時間:
2021-2-20 10:24
public class XD {
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);
}
}
複製代碼
作者:
李柏穎
時間:
2021-2-20 10:24
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);
}
}
複製代碼
作者:
陳莉榛
時間:
2021-2-20 10:26
package a01;
public class a01 {
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);
}
}
複製代碼
作者:
龔品誠
時間:
2021-2-20 10:27
package owo;
public class owo {
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",d);
System.out.printf("%.0f%n",c);
System.out.printf("%9.2f%n",d);
System.out.printf("%9.2f%n",a);
System.out.printf("%09.2f%n",b);
System.out.printf("%09.2f%n",a);
}
}
複製代碼
作者:
張淯祺
時間:
2021-2-20 10:27
package a01;
public class a01 {
public static void main(String[] args) {
double x=3.456789;
double y=34.56789;
double z=345.6789;
double a=3456.789;
System.out.printf("%.1f%n",z);
System.out.printf("%.0f%n",a);
System.out.printf("%9.2f%n",x);
System.out.printf("%9.2f%n",y);
System.out.printf("%09.2f%n",z);
System.out.printf("%09.2f%n",a);
}
}
複製代碼
作者:
王銘鴻
時間:
2021-2-20 10:27
public class a01 {
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);
}
}
複製代碼
作者:
朱閎聿
時間:
2021-2-20 10:28
package a01;
public class a01 {
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);
}
}
複製代碼
作者:
李穎俊
時間:
2021-2-20 10:29
package oo;
public class o1 {
public static void main(String[] args) {
double x=3.456789;
double y=34.56789;
double n=345.6789;
double o=3456.789;
System.out.printf("%.1f%n",o);
System.out.printf("%.0f%n",y);
System.out.printf("%9.2f%n",x);
System.out.printf("%9.2f%n",n);
System.out.printf("%09.2f%n",o);
System.out.printf("%09.2f%n",x);
}
}
複製代碼
作者:
黃柏智
時間:
2021-2-20 10:35
public class A02 {
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);
}
}
複製代碼
作者:
黃柏智
時間:
2021-2-20 11:43
public class A02 {
public static void main(String[] args) {
String str1="dog";
String str2="cat";
int a=4,b=6;
System.out.printf("there are %d %Ss and %d %Ss",a,str1,b,str2);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2