Discuss / Java / 练习

练习

Topic source

#1 Created at ... [Delete] [Delete and Lock User]
public class Hello {    public static void main(String[] args){           Hero geluo = new Hero();           geluo.name="盖伦";           geluo.Hp = 500;           geluo.armor = geluo.Hp/4;          System.out.println(geluo.detailed());        System.out.println(" ");        Hero geluo1 = new Hero();        geluo1.name="迪莫";        geluo1.Hp = 200;        geluo1.armor = geluo1.Hp/4;        System.out.println(geluo1.detailed());    }}class Hero {    public String name;    public int  Hp;    public int  armor;    public  void  setName(String name){          this.name = name;    }    public  String getName(){         return  this.name;    }    public void  setHp(int hp){         this.Hp = hp;    }    public int getHp(){         return  this.Hp;    }    public void setArmor(int armor){        this.armor = armor;    }    public  int getArmor(){         return  this.armor;    }    public  String detailed(){        return  "英雄的名字:"+this.name+'\n'+"英雄的血量:"+this.Hp+'\n'+"英雄的护甲:"+this.armor;    }}

  • 1

Reply