1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | package 패키지 이름이 있는 ; import java.util.ArrayList; import java.util.Iterator; public class 클래스 이름이 있는 위치 { ArrayList<Integer> numList; public void Test2() { numList = new ArrayList<>(); numList.add(100); numList.add(300); numList.add(400); for (Integer oNum : numList) { System.out.println(oNum); } numList.add(1,200); Iterator<Integer> iNum= numList.iterator(); int monsterHP=0; int checkNum=0; float fullHP=0; while(iNum.hasNext()) { checkNum++; monsterHP = iNum.next(); fullHP = monsterHP; while(monsterHP>0) { System.out.println(String.format("%2d번째 몬스터를 한대 때립니다.",checkNum)); monsterHP -= 45; System.out.println(String.format(" 몬스터의 체력은 %3d 남았고 전체 체력의 %.1f 남았습니다.",monsterHP,(monsterHP/fullHP)*100)); } } } } | cs |
'정리 카테고리 > JAVA & 이클립스' 카테고리의 다른 글
JAVA_입력받는 BufferedReader 와 Scanner (0) | 2018.04.17 |
---|---|
JAVA_ Exception 종류와 원인 List (try catch 문) (0) | 2018.04.17 |
JAVA_파일 구조를 위한 Serch (0) | 2018.04.16 |
JAVA_ArrayList & Iterator (0) | 2018.04.16 |
JAVA_해쉬 테이블 간단 예제 (0) | 2018.04.16 |