返回列表 發帖
本帖最後由 鄭楀諺 於 2018-10-20 15:05 編輯
  1. package Morris;

  2. public class Main {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5.         Dog dog =new Dog("Momo","blue",2,1.3);
  6.         dog.showProfile();
  7.         dog.makesound(3);
  8.         }

  9. }
  10. package Morris;

  11. public class Dog {
  12.     String name;
  13.     String color;
  14.     int age;
  15.     double weight;
  16.     public void showProfile()
  17.     {
  18.             System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色為%s", this.name,this.age,this.weight,this.color));
  19.     }
  20.     public void makesound(int n)
  21.     {
  22.             for(int i=0;i<n;i++)
  23.             {
  24.                     System.out.print("汪~");
  25.             }
  26.         System.out.println();
  27.     }
  28.     Dog(String name,String color,int age,double weight)
  29.     {
  30.             this.name=name;
  31.             this.color=color;
  32.             this.age=age;
  33.             this.weight=weight;
  34.     }
  35. }
複製代碼

TOP

  1. package Morris;

  2. public class Dog {
  3.     String name;
  4.     String color;
  5.     int age;
  6.     double weight;
  7.     public void showProfile()
  8.     {
  9.             System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色為%s", this.name,this.age,this.weight,this.color));
  10.     }
  11.     public void makesound(int n)
  12.     {
  13.             for(int i=0;i<n;i++)
  14.             {
  15.                     System.out.print("汪~");
  16.             }
  17.         System.out.println();
  18.     }
  19.     Dog(String name,String color,int age,double weight)
  20.     {
  21.             this.name=name;
  22.             this.color=color;
  23.             this.age=age;
  24.             this.weight=weight;
  25.     }
  26. }
複製代碼

TOP

返回列表