本帖最後由 鄭楀諺 於 2018-10-20 15:05 編輯
- package Morris;
- public class Main {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Dog dog =new Dog("Momo","blue",2,1.3);
- dog.showProfile();
- dog.makesound(3);
- }
- }
- package Morris;
- public class Dog {
- String name;
- String color;
- int age;
- double weight;
- public void showProfile()
- {
- System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色為%s", this.name,this.age,this.weight,this.color));
- }
- public void makesound(int n)
- {
- for(int i=0;i<n;i++)
- {
- System.out.print("汪~");
- }
- System.out.println();
- }
- Dog(String name,String color,int age,double weight)
- {
- this.name=name;
- this.color=color;
- this.age=age;
- this.weight=weight;
- }
- }
複製代碼 |