標題:
printf() 函式
[打印本頁]
作者:
tonyh
時間:
2013-4-20 16:08
標題:
printf() 函式
本帖最後由 tonyh 於 2013-4-20 16:35 編輯
利用 printf() 函式, 規範輸出字串的格式.
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n"; // %d 輸出整數 %n 換行
String b="There are %f cats and %.2f dogs.%n"; //%f 輸出浮點數 .2 四捨五入至小數後第二位
String c="There are %s cats, %d dogs, %s pigs, and %d rabbits.%n"; //%s 字串
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
作者:
劉漢文
時間:
2013-4-20 16:43
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n";
String b="There are %f cats and %.2f dogs.%n";
String c="There are %s cats, %d dogs, %s pigs, and %d rabbits.%n";
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
作者:
t2364705
時間:
2013-4-20 16:44
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n";
String b="There are %f cats and %.2f dogs.%n";
String c="There are %s cats, %d dogs, %s pig, and %d ribbit.%n";
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
作者:
黃博鴻
時間:
2013-4-20 16:44
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n";
String b="There are %f cats and %.2f dogs.%n";
String c="There are %s cats and %d dogs,%s pigs,and %d rabbits.%n";
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
作者:
t3742238
時間:
2013-4-20 16:45
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n";
String b="There are %f cats and %.2f dogs.%n";
String c="There are %s cats, %d dogs, %s pigs, and %d rabbits.%n";
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
作者:
尤泓鈞
時間:
2013-4-20 16:47
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n";
String b="There are %f cats and %.2f dogs.%n";
String c="There are %s cats, %d dogs, %s pigs, and %d rabbits.%n";
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
作者:
蔡昀佑
時間:
2013-4-20 16:47
public class ch63
{
public static void main(String args[])
{
String a="There are %d cats and %d dogs.%n";
String b="There are %f cats and %.2f dogs.%n";
String c="There are %s cats, %d dogs, %s pigs, and %d rabbits.%n";
System.out.printf(a,5,7);
System.out.printf(b,5.0,7.0);
System.out.printf(c,"5",7,"2",3);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2