標題:
printf() 輸出練習
[打印本頁]
作者:
tonyh
時間:
2021-1-27 13:43
標題:
printf() 輸出練習
試以 printf() 方法做字串輸出。
%d 整數
%s 字串
%S 轉換為大寫字母的字串
%.2f 四捨五入至小數點後2位
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);
}
}
複製代碼
作者:
卓炘暘
時間:
2021-1-27 13:56
import java.util.Scanner;
public class Ch01
{
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);
}
}
複製代碼
作者:
劉凱閔
時間:
2021-1-27 13:56
public class Ch05 {
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);
}
複製代碼
作者:
王睿宇
時間:
2021-1-27 13:56
public class AS02 {
public static void main(String[] args) {
String a="dog", b="cat";
int x=7, y=4;
double n=35.1493;
System.out.printf("There are %d %Ss and %d %ss and totally weight %.2f pounds",x,a,y,b,n);
}
}
複製代碼
作者:
吳聲寬
時間:
2021-1-27 13:56
public class Ch10
{
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);
}
}
複製代碼
作者:
李柏穎
時間:
2021-1-27 13:56
import java.util.Scanner;
public class Ch01
{
public static void main(String[] args)
{
String str1="dog", str2="cat";
int a=3, b=5;
double c=21.3568;
System.out.printf("There are %d %ss and %d %Ss totallt weight %.2f pounds",a,str1,b,str2,c);
}
}
複製代碼
作者:
楊澤全
時間:
2021-1-27 13:56
public class Ch08
{
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);
}
}
複製代碼
作者:
楊小萱
時間:
2021-1-27 13:57
public class Ch05
{
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);
}
}
複製代碼
作者:
紀承典
時間:
2021-1-27 13:58
public class Ch50 {
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);
}
}
複製代碼
作者:
王博裕
時間:
2021-1-27 13:58
import java.util.Scanner;
public class Ch05 {
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 weight %.2f pounds.",a,str1,b,str2,total);
}
}
複製代碼
作者:
藍健洲
時間:
2021-1-27 13:59
public class Ch01 {
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 pound.",a,str1,b,str2,total);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2