返回列表 發帖
  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. public class Dog {
  8.     String name;
  9.     int age;
  10.     double weight;
  11.     String color;
  12.    
  13.     public void ShowProfile()
  14.     {
  15.      System.out.println(String.format("%s今年%d歲,體重%f公斤毛色%s",this.name,this.age,this.weight,this.color));
  16.     }
  17.     public void makesound(int n)
  18.     {
  19.     for(int i=0;i<n;i++)
  20.     {
  21.     System.out.print("汪~");
  22.     }
  23.     System.out.println();
  24.     }
  25.     dog(String name,int age,double weight,String color)
  26.     {
  27.          this.name=name;
  28.          this.age=age;
  29.          this.weight=weight;
  30.          this.color=color;
  31.    }
  32.    
  33. }
  34.         }

  35. }
複製代碼

TOP

返回列表