返回列表 發帖
  1. public class a02 {
  2. public static void main(String[] args) {
  3.         Dog a=new Dog("憨憨",2,1.3f,"紅棕色");
  4.         Dog b=new Dog("球球",1,1.2f,"白色");
  5.         a.showProfile();
  6.         a.makeshound(2);
  7.         b.showProfile();
  8.         b.makeshound(3);
  9. }
  10. }
  11. class Dog
  12. {
  13. String name,c;
  14. int s;
  15. float x;
  16. Dog(String name,int s,float x, String c)
  17. {
  18.          this.name=name;
  19.          this.s=s;
  20.          this.x=x;
  21.          this.c=c;
  22. }
  23. void showProfile()
  24. {
  25.          System.out.println(this.name+"今年"+this.s+"歲,體重"+this.x+"公斤,毛色為"+c);
  26. }
  27. void makeshound(int n)
  28. {
  29.          for(int i=1; i<=n; i++)
  30.          {
  31.                  System.out.print("汪");
  32.                  System.out.println();
  33.          }
  34. }
  35. }
複製代碼

TOP

返回列表