Skip to content

랜덤 픽 코드를 개선해보자 #4

@lkdcode

Description

@lkdcode
public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    List<String> nameList = new ArrayList<>();

    System.out.print("인원수를 입력해주세요 : ");
    int size = Integer.parseInt(br.readLine());
    int min = 0;

    for (int i = 0; i < size; i++) {
        System.out.print("이름을 입력해주세요 : ");
        nameList.add(br.readLine());
    }

    int index = SecureRandom.getInstanceStrong().nextInt(size - min) + min;

    System.out.println(nameList.get(index));
}

위의 코드를 챕터 1~4 내용을 기준으로 수정해보면 좋을 것 같아요

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions