返回列表 發帖

printf() 輸出練習

試以 printf() 方法做字串輸出。
%d 整數
%s 字串
%S 轉換為大寫字母的字串
%.2f 四捨五入至小數點後2位

  1. public class Ch60
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         String str1="dog", str2="cat";
  6.         int a=3, b=5;
  7.         double total=21.3568;
  8.         System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
  9.     }
  10. }
複製代碼

  1. public class junior
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         String str1="dog", str2="cat";
  6.         int a=3, b=5;
  7.         double total=21.3568;
  8.         System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
  9.     }
  10. }
複製代碼

TOP

  1. package asdf;
  2. import java.util.Scanner;
  3. public class QWER
  4. {
  5.      public static void main(String[] args)
  6.      {
  7.              String str1="dogs",str2="cats";
  8.              int n=3,a=5;
  9.              double t=21.3568;
  10.          System.out.printf("There are %d %s and %d %s totally weigh %.2f pounds.",n,str1,a,str2,t);
  11.      }
  12. }
複製代碼
我是眾神之王XXX  I love you
0000000000

TOP

  1.     public static void main(String[] args)
  2.     {
  3.         String str1="dog", str2="cat";
  4.         int a=3, b=5;
  5.         double total=21.3568;
  6.         System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds."
  7.                         ,a,str1,b,str2,total);
  8.     }
複製代碼

TOP

  1. package text369;
  2. import java.util.Scanner;
  3. public class text45 {
  4.         public static void main(String[] args) {
  5.                 String str1="dog",str2="cat";
  6.                 int x=3,y=4;
  7.                 double total=21.3568;
  8.                 System.out.printf("there are %d %ss and %d %Ss totally weigh %.2f pounds.",x,str1,y,str2,total);
  9.                
  10.                
  11.         }

  12. }
複製代碼
張閎鈞OuO

TOP

  1. import java.util.Scanner;

  2. public class Ch11 {
  3.         public static void main(String[] args) {
  4.                 String str1="dog",str2="cat";
  5.                 int a=3,b=5;
  6.                 double total = 21.3586;
  7.                 System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds."
  8.                                 ,a,str1,b,str2,total);
  9.         }

  10. }
複製代碼

TOP

  1. public class z {
  2.         public static void main(String[] args)
  3.         {
  4.                 String dog = "dog", cat = "cat";
  5.                 int three = 3, five = 5;
  6.                 double total = 21.3568;
  7.                 System.out.printf("there are %d %ss and %d %Ss totally weigh %.2f pound.", three,dog, five, cat,total);
  8.         }
  9. }
複製代碼

TOP

  1. import java.util.*;

  2. public class Ch01 {
  3.        
  4.         public static void main(String[] args)
  5.      {
  6.                 String a="dog",b="cat";
  7.                 int d=3;
  8.                 int c=5;
  9.                 double total=21.3568;
  10.                 System.out.printf("There is %d %ss and %d %Ss totally weigh %.2f pounds.",d,a,c,b,total);
  11.      }
  12. }
複製代碼

TOP

  1. public class Ch09
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         String str1="dog", str2="cat";
  6.         int a=3, b=5;
  7.         double total=21.3568;
  8.         System.out.printf("There are %d %ss and %d %Ss totally weigh %.2f pounds.",a,str1,b,str2,total);
  9.     }
  10. }
複製代碼

TOP

返回列表