返回列表 發帖

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. package blueming;

  2. public class blueming {

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

  9. }
複製代碼

TOP

  1. public class Ch01{
  2.         public static void main(String args[]){
  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 weith %.2f pounds.",a,str1,b,str2,total);
  7.         }
  8. }
複製代碼

TOP

  1. public class Ch60 {

  2.         public static void main(String[] args) {

  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.",a,str1,b,str2,total);
  7.         }


  8. }
複製代碼

TOP

  1. import java.util.Scanner;

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

TOP

  1. public class Ch01 {

  2.         public static void main(String[] args) {
  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",a,str1,b,str2,total);
  7.         }
  8. }
複製代碼

TOP

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

TOP

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

TOP

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

TOP

  1. public class Ch01
  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. public class Ch1
  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. public class Ch46 {

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

  9. }
複製代碼

TOP

  1. package ggg;

  2. import java.util.Scanner;


  3. public class Ch40{

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

TOP

返回列表