標題:
printf() 輸出練習
[打印本頁]
作者:
tonyh
時間:
2019-1-25 13:40
標題:
printf() 輸出練習
本帖最後由 tonyh 於 2019-7-3 21:50 編輯
試以 printf() 方法做字串輸出。
%d 整數
%s 字串
%S 轉換為大寫字母的字串
%.2f 四捨五入至小數點後2位
[attach]5787[/attach]
public class Ch60
{
public static void main(String[] args)
{
String str1="dog", str2="cat";
int a=3, b=5;
double total=21.3568;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
作者:
趙一鳴
時間:
2019-1-25 14:10
public class Ch13
{
public static void main(String[] args)
{
int a=3,;
double c=21.32231;
String d="你好",e="dogs";
System.out.printf("I hava %d %S and %.2f cats and they can say %s",
a,e,c,d);
}
}
複製代碼
作者:
孫焌仁
時間:
2019-1-25 14:10
import java.util.Scanner;
public class Ch10
{
public static void main(String args[])
{
String str1="dog",str2="cat";
int f=9,b=10;
double total=45.5543769;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f "
+"pounds.",f,str1,b,str2,total);
}
}
複製代碼
作者:
楊于暄
時間:
2019-1-25 14:12
public class Ch35
{
public static void main(String[] args)
{
String str1="dog", str2="cat";
int a=3, b=5;
double total=21.3568;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
作者:
林育鋐
時間:
2019-1-25 14:12
public class Ch60
{
public static void main(String[] args)
{
String str1="dog", str2="cat";
int a=3, b=5;
double total=21.3568;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
作者:
王騰立
時間:
2019-1-25 14:15
public class Ch24
{
public static void main(String[] args)
{
String str1="dog", str2="cat";
int a=3, b=5;
double total=21.3568;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
作者:
楊貳鈞
時間:
2019-1-25 14:16
public class Ch04
{
public static void main(String[] args)
{
String str1="dog",str2="cat";
int a=3,b=5;
double total=21.3568;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
作者:
may
時間:
2019-1-25 14:37
import java.util.Scanner;
public class Ch50 {
public static void main(String[] args){
int a = 3,b = 5;
String str1 = "cat",str2="dog";
double total = 45.213568;
System.out.printf("There are %d %ss and %d %SS totally weigh %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2