标签:for [] foo int log stat bsp system pow
//英雄类 public class Hero { String name; int power=100;//满血 //增加体力 void eat(String food,int value){ System.out.println(this.name+"吃了"+food+"增加血量"); power=(power+value>100)?100:(power+value); } //受到伤害 void hurt(){ power-=20; System.out.println("你伤害了我,还一笑而过"); if(power<=0){ System.out.println(name+"over"); } } }
public class Test { public static void main(String[] args) { Hero h=new Hero(); h.name="德玛西亚"; h.eat("大血瓶",50); for(int i=0;i<2;i++){ h.hurt(); } h.eat("烤冷面",30); } }
标签:for [] foo int log stat bsp system pow
原文地址:http://www.cnblogs.com/zyy1130/p/6666481.html