返回列表 發帖
  1. public class Main {

  2.         public static void main(String[] args) {
  3.                 // TODO 自動產生的方法 Stub
  4.      dog dog =new dog("憨憨",1,1.3,"紅棕色");
  5.            dog.ShowProfile();
  6.            dog.makesound(3);
  7.         }

  8. }
複製代碼
  1. public class dog {
  2.    String name;
  3.    int age;
  4.    double weight;
  5.    String color;
  6.    
  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,int age,double weight,String color)
  20.    {
  21.          this.name=name;
  22.          this.age=age;
  23.          this.weight=weight;
  24.          this.color=color;
  25.    }
  26.    
  27. }
複製代碼

TOP

返回列表