|
|
back to board№12 Pls help. What's wrong with my code? Java import java.math.BigDecimal; import java.util.Arrays; import java.util.Scanner;
public class main {
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) { int candidates = in.nextInt(); int electors = in.nextInt(); int votes[] = new int[electors]; int summ = 0; double onePercent = (double) electors / 100;
for(int x = 0; x < electors; x++) { votes[x] = in.nextInt(); }
Arrays.sort(votes); int VoteNum = 1; int startOfNextSearch = 0;
while(candidates != 0) { for(int x = startOfNextSearch; x < electors; x++) { if(x > startOfNextSearch && votes[x] == votes[x -1] && votes[x] == VoteNum) { summ++; } else if(votes[x] == VoteNum) { summ++; } else { x = electors; } } BigDecimal Part = new BigDecimal(Double.toString((double) summ / onePercent)); Part = Part.setScale(2, BigDecimal.ROUND_HALF_UP); if((Part.doubleValue() + 1) % 1 == 0) { System.out.println(Part.doubleValue() + "0%"); } else { System.out.println(Part.doubleValue() + "%"); } VoteNum++; startOfNextSearch += summ ; summ = 0; candidates--; }
} }
Edited by author 26.07.2015 16:16 |
|
|