返回列表 發帖
本帖最後由 梁和雋 於 2016-7-8 20:57 編輯
  1. public class Ch1010101010111101010101010101010101020101010
  2. {
  3.   public static void main(String args[])
  4.   {
  5.     Dog d1=new Dog("憨憨",2,1.3f,"紅棕色");
  6.     Dog d2=new Dog("球球",1,1.2f,"白色");
  7.     d1.showProfile();
  8.     d1.makeSound(2);
  9.     d2.showProfile();
  10.     d2.makeSound(3);
  11.   }
  12. }
  13. class Dog
  14. {
  15.   String name, color;
  16.   int age;
  17.   float weight;
  18.   Dog(String name, int age, float weight, String color){
  19.     this.name=name;
  20.     this.age=age;
  21.     this.weight=weight;
  22.     this.color=color;
  23.   }
  24.   void showProfile()
  25. {
  26.     System.out.println(name+"今年"+age+"歲,體重"+weight+"公斤,毛色為"+color);
  27. }
  28.   void makeSound(int n)
  29.   {
  30.     for(int i=-2; i<n; i++)
  31.       System.out.print("喵~/(^_^)\\ ");
  32.     System.out.println();
  33.   }
  34. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

返回列表