개발자가 되기까지 (2023.08.16~2024.04.15)/[Basic] Java2023. 11. 23. 22:19[Java] HashMap으로 간단한 단어장 만들기

입력할 단어 개수를 정하여 단어와 의미를 직접 입력하고 HashMap으로 간단한 단어장 만들기 import java.util.HashMap; import java.util.Scanner; public class SimpleWord { public static void main(String[] args) { HashMap map = new HashMap(); Scanner scan = new Scanner(System.in); System.out.print("단어 개수 : "); int num = scan.nextInt(); while(map.size() "); String word = scan.next(); System.out.print("의미> "..

개발자가 되기까지 (2023.08.16~2024.04.15)/[Basic] Java2023. 9. 8. 21:52[Java] 주사위 게임 (무한루프 while)

주사위는 1~6 사이의 수를 랜덤으로 주고 총 30칸을 이동하면 완주 public class 주사위게임 { public static void main(String[] args) { int goal = 30; int count = 0; // 무한 루프를 주고 while (true) { int dice = (int) (Math.random() * 6) + 1; goal -= dice; count++; System.out.println("주사위 : " + dice); System.out.println(dice + "칸 이동"); System.out.println(goal + "칸 남았습니다."); // 도착했을 때 break로 무한루프를 빠져나간다 if(goal

개발자가 되기까지 (2023.08.16~2024.04.15)/[Basic] Java2023. 9. 3. 00:25[Java] 1부터 50까지 짝수만 출력 (while, if)

1부터 50까지 짝수만 출력하라. 단, 5개씩 1줄로 출력해야한다. public class While02 { public static void main(String[] args) { int i = 1;// i 초기화 int cnt = 0;// 숫자 카운트용 while (i

개발자가 되기까지 (2023.08.16~2024.04.15)/[Basic] Java2023. 9. 3. 00:13[Java] 1부터 10까지 출력 (while, if)

1부터 10까지 출력 public class While01 { public static void main(String[] args) { // 1~10까지 짝수만 출력 int i = 1;// i 초기값 설정 while (i < 11) {// i가 11이라면 멈춘다 if(i % 2 == 0 ) { System.out.print(i+" "); } i++;// if문이 끝나면 i를 1씩 증가시킨다. // i++을 해주지 않으면 i는 초기값인 1에서 변하지 않는다. } } } [Java] 1부터 10까지 출력 (while, if) 끝! (다음 게시물 예고편) [Java] 1부터 50까지 짝수만 출력 (while, if)

728x90
반응형
image