返回列表 發帖
  1. package owo;

  2. public class owo {

  3.         public static void main(String[] args)
  4.         {
  5.                 Dog red=new Dog("憨憨",2,1.3f,"紅棕色");
  6.                 Dog white=new Dog("球球",1,1.2f,"白色");
  7.                 red.show();
  8.                 red.shound(2);
  9.                 white.show();
  10.                 white.shound(3);
  11.                
  12.                
  13.         }

  14. }
  15. class Dog
  16. {
  17.         String name,color;
  18.         int y;
  19.         float kg;
  20.        
  21.         Dog(String x,int u,float h,String p)
  22.         {
  23.                 name=x;
  24.                 y=u;
  25.                 kg=h;
  26.                 color=p;
  27.         }
  28.         void show()
  29.         {
  30.                 System.out.println(name+"今年"+y+"歲、"+kg+"公斤、毛色為"+color);
  31.         }
  32.         void shound(int n)
  33.         {
  34.                 for(int i=0;i<n;i++)
  35.                 {
  36.                         System.out.print("汪~");
  37.                 }
  38.                 System.out.println();
  39.         }
  40. }
複製代碼

TOP

返回列表