標題:
printf() 輸出練習
[打印本頁]
作者:
陳品肇
時間:
2019-7-5 13:21
標題:
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);
}
}
複製代碼
作者:
蔣宗儒
時間:
2019-7-5 13:31
public class junior
{
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-7-5 13:32
package asdf;
import java.util.Scanner;
public class QWER
{
public static void main(String[] args)
{
String str1="dogs",str2="cats";
int n=3,a=5;
double t=21.3568;
System.out.printf("There are %d %s and %d %s totally weigh %.2f pounds.",n,str1,a,str2,t);
}
}
複製代碼
作者:
黃恆嘉
時間:
2019-7-5 13:32
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-7-5 13:33
package text369;
import java.util.Scanner;
public class text45 {
public static void main(String[] args) {
String str1="dog",str2="cat";
int x=3,y=4;
double total=21.3568;
System.out.printf("there are %d %ss and %d %Ss totally weigh %.2f pounds.",x,str1,y,str2,total);
}
}
複製代碼
作者:
潘承渙
時間:
2019-7-5 13:41
import java.util.Scanner;
public class Ch11 {
public static void main(String[] args) {
String str1="dog",str2="cat";
int a=3,b=5;
double total = 21.3586;
System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds."
,a,str1,b,str2,total);
}
}
複製代碼
作者:
呂昀宸
時間:
2019-7-5 13:43
public class z {
public static void main(String[] args)
{
String dog = "dog", cat = "cat";
int three = 3, five = 5;
double total = 21.3568;
System.out.printf("there are %d %ss and %d %Ss totally weigh %.2f pound.", three,dog, five, cat,total);
}
}
複製代碼
作者:
湯東緯
時間:
2019-7-5 13:46
import java.util.*;
public class Ch01 {
public static void main(String[] args)
{
String a="dog",b="cat";
int d=3;
int c=5;
double total=21.3568;
System.out.printf("There is %d %ss and %d %Ss totally weigh %.2f pounds.",d,a,c,b,total);
}
}
複製代碼
作者:
黃安立
時間:
2019-7-5 13:47
public class Ch09
{
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);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2