#파라미터로 객체 전달 ## CODE <a class='btn btn-default' href='/codes/10740'>Link</a> ``` public class HeroTest3 { public static void main(String[] ar) { Hero3 thor = new Hero3("토르", 200); Hero3 thanos = new Hero3("타노스", 150); thor.punch(thanos); thanos.punch(thor); thor.punch(thanos); thanos.punch(thor); thor.punch(thanos); thanos.punch(thor); } } class Hero3 { String name; int hp; Hero3 (String n, int h) { name = n; hp = h; } public void punch(Hero3 enemy) { enemy.hp -= 10; System.out.printf("[%s]의 펀치!! -> [%s]의 hp : %d\n", name, enemy.name, enemy.hp); } } ``` ## INPUT ``` ``` ## OUPUT ``` [토르]의 펀치!! -> [타노스]의 hp : 140 [타노스]의 펀치!! -> [토르]의 hp : 190 [토르]의 펀치!! -> [타노스]의 hp : 130 [타노스]의 펀치!! -> [토르]의 hp : 180 [토르]의 펀치!! -> [타노스]의 hp : 120 [타노스]의 펀치!! -> [토르]의 hp : 170 ``` 위 코드에서 상대방의 체력이 0이 될 떄까지 punch 메소드를 실행하려면 반복문을 어떻게 짜야 할까요? 코딩에 소질이 없나 봐요.. 감이 안 잡히네요..ㅠㅠ
# 상대 체력이 바닥날 때 까지 ``` while (thanos.hp > 0) { thor.punch(thanos); } ``` ## PS. 원래 처음엔 다 어려워요. 영어 이제 막 배웠는데, 바로 일기 쓰라고 하면 못쓰잖아요? 비슷한거죠~ 훈련의 시간이 필요합니다! 일단 지금은 따라하는 것부터 시작해보세요.