大家好,我是小小根,我来为大家解答以上问题。为什么java打不开,为什么我的JAV程序运行不了很多人还不知道,现在让我们一起来看看吧!
package com.sfcc09003; public class f { public static void main(String[] args) { Person p1 = new Person(); p1.name = "奥特曼"; p1.attackPower = 100; p1.healthPoint = 1000;
Person p2 = new Person(); p2.name = "小怪兽"; p2.attackPower = 60; p2.healthPoint = 1500;
while (true) { if (p2.attack(p1)) { break; } if (p1.attack(p2)) { break; } } } }; //不用分号
package com.sfcc09003;
public class Person { String name; int attackPower; int healthPoint;
public boolean attack(Person p) { System.out.println(name + "攻击" + p.name); if (p.hurt(attackPower)) { System.out.println(name + "生命值还剩" + p.healthPoint); return true; } else { return false; } }
public boolean hurt(int attackPower) { healthPoint -= attackPower; System.out.println(name + "生命减少" + attackPower + "还剩" + healthPoint); if (healthPoint <= 0) { System.out.println(name + "挂了!!!"); return ture; // 单词到错true } else { return false; } } } 望采纳
本文到此讲解完毕了,希望对大家有帮助。