【发布时间】:2011-06-03 00:31:52
【问题描述】:
我需要知道每个人有多少票。我有一个计数,计算有多少候选人在比赛中是 5。现在我有一堆来自数组列表的数字,我需要计算每个候选人的快乐投票,候选人的数量根据我使用的数组列表而变化,但是出于测试目的,我使用的是 test5,它有 5 个。
//Numbers from arraylist:
1
1
2
5
2
5
5
5
这是我的代码
// My code
for (int i=1; i <output.size(); i++){
char checkBallot = output.get(i).charAt(1);
//candidate is array to track how many output as what
// output is array of numbers I want to count.
String aString = Character.toString(checkBallot);
int c = Integer.parseInt(aString);
int b = c;
for (int p= 0; p < count; p++){
if(c == p+1){
int oldvalue =0;
candidate[c] = c+ oldvalue ;
oldvalue = c ;
System.out.println("this is the counter:" +c);
}
}
【问题讨论】:
-
另外,粘贴其余代码...输出是什么?状态?候选人?等
-
输出是数组列表中的数字,状态是现在状态的顺序是1。候选者是一个数组,用于跟踪输出中有多少 1 2 3 4 5。抱歉,我写我想要达到的目标很糟糕。
-
@oli 我想计算输出数组列表中有多少个 1,2,3,4,5。并将每个的数量存储到候选中。