【发布时间】:2014-09-22 09:31:25
【问题描述】:
每当我尝试编译这个函数时,它都会在第 10 行给出一个错误 --> ErrorMessage : CandidateCode.java.10: static HashMap hm = new HashMap() 类型的非法开始; 1 个错误 我正在尝试在网站的编译器上编译它,但是当我使用 netbeans 时它完全可以正常工作。
import java.util.*;
public class CandidateCode {
static int rep, total = 0, sum = 0, i = 0, j = 0;
static HashMap<Integer, Integer> hm = new HashMap<>();
static ArrayList<Integer> al;
public static int DistributingMedals(int input1, int[] input2, int[] input3,
int[] input4, int input5) {
//Write code here
for (i = 0; i < input1; i++) {
int start = input3[i];
int end = input4[i];
int count = input2[i];
for (j = start; j <= end; j++) {
try {
sum = hm.get(j);
} catch (Exception e) {
e.getMessage();
sum = 0;
}
sum = sum + count;
hm.put(j, sum);
}
}
int chk = 0;
Collection<Integer> valcol = hm.values();
casper:
while (chk < valcol.size()) {
for (int max : valcol) {
total = max + total;
if (total > input5) {
al = new ArrayList(hm.keySet());
Object obj = al.get(chk);
rep = (Integer) obj;
break casper;
}
chk++;
}
}
return rep;
}
}
【问题讨论】: