Skip to content

Instantly share code, notes, and snippets.

@FeelingXD
Last active January 5, 2023 14:06
Show Gist options
  • Save FeelingXD/4975862c10f1e1a1e2f4cddb691702e0 to your computer and use it in GitHub Desktop.
Save FeelingXD/4975862c10f1e1a1e2f4cddb691702e0 to your computer and use it in GitHub Desktop.
투표 시뮬레이터
/*
작성자: 고지민
*/
import java.util.*;
public class Main {
public static void main(String[] args) {
run(10000);
}
public static void run(int end){ // end 최대값
Random rnd = new Random(System.currentTimeMillis());
int vote;
String[] politicians={"이재명","윤석열","심상정","안철수"};
int[] votes={0,0,0,0};
for(int i=0 ;i<end;i++){
vote=rnd.nextInt(4);
System.out.printf("[투표진행율]: %02.2f%%, %d명 투표 => %s\n" ,(double)i/end*100,i+1,politicians[vote]);
votes[vote]+=1;
for(int j=0;j< politicians.length;j++) {
System.out.printf("[기호:%d] %s : %02.2f%%, (투표수: %d)\n", j + 1, politicians[j], (double) votes[j] / end*100, votes[j]);
}
System.out.println();
}
int max=0;
int max_index=0;
for(int i=0;i<votes.length;i++){
if(votes[i]>max){
max=votes[i];
max_index=i;
}
}
System.out.printf("[투표결과] 당선인: %s",politicians[max_index]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment