인구조사

2026년 4월 9일 09:30분

민수기 1장은 이스라엘 12지파의 병력을 세는 인구조사입니다. 각 지파의 이름과 숫자를 입력하면 전체 합계가 나옵니다. 나는 지파 이름을 키로, 인원을 값으로 하는 Map을 만들어 집계했습니다.

package com.jesusbornd.numbers;

import java.util.LinkedHashMap;
import java.util.Map;

public class Numbers_01_Chapter_Lv1 {

    public static void main(String[] args) {
        Map<String, Integer> census = new LinkedHashMap<>();
        census.put("르우벤", 46500);
        census.put("시므온", 59300);
        census.put("갓",     45650);
        census.put("유다",   74600);
        census.put("잇사갈", 54400);
        census.put("스불론", 57400);
        census.put("에브라임",40500);
        census.put("므낫세", 32200);
        census.put("베냐민", 35400);
        census.put("단",     62700);
        census.put("아셀",   41500);
        census.put("납달리", 53400);

        int total = 0;
        for (Map.Entry<String, Integer> e : census.entrySet()) {
            System.out.printf("%-8s %,d명%n", e.getKey(), e.getValue());
            total += e.getValue();
        }
        System.out.println("──────────────");
        System.out.printf("합계       %,d명%n", total);
    }
}

census = {
    "르우벤":  46500,
    "시므온":  59300,
    "갓":      45650,
    "유다":    74600,
    "잇사갈":  54400,
    "스불론":  57400,
    "에브라임":40500,
    "므낫세":  32200,
    "베냐민":  35400,
    "단":      62700,
    "아셀":    41500,
    "납달리":  53400,
}

for tribe, count in census.items():
    print(f"{tribe:<6} {count:,}명")

print("──────────────")
print(f"합계   {sum(census.values()):,}명")

Comments

Avatar
 2026년 4월 9일 20:01분

모두를 한 명씩 세어가는 과정에서 각자가 얼마나 소중한지 느껴졌어요.



Search

← 목록으로