返回列表 發帖
  1. package bbs.istak.org.tw;

  2. public class Main {

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

  9. }
複製代碼
寶寶心裡苦,但寶寶不說。

TOP

  1. package bbs.istak.org.tw;

  2. public class Dog {
  3.         int age;
  4.         double weight;
  5.         String name;
  6.         String color;
  7.         public void showProfile() {
  8.                 System.out.println(
  9.                                 String.format("%s今年%d歲,體重%f公斤,毛色為%s",this.name,this.age,this.weight,this.color)
  10.                                 );
  11.         }
  12.         public void        makeSound(int n){
  13.                 for(int i=0;i<=n;i++)
  14.                     System.out.print("汪~");
  15.                 System.out.println();
  16.         }
  17.     Dog(int Age,double Weight,String Name,String Color){
  18.               this.age=Age;
  19.               this.weight=Weight;
  20.               this.name=Name;
  21.               this.color=Color;

  22.        }
  23.        
  24. }
複製代碼
寶寶心裡苦,但寶寶不說。

TOP

返回列表