我试着写这段代码,但我认为它看起来不太好:)
请. .我可以用for循环来创建这个方法吗?以及如何?
static public void add_ConstantVote(Contestant [] contestant){
contestant[0].setVoteScored(8, 0);
contestant[0].setVoteScored(7, 1);
contestant[0].setVoteScored(6, 2);
contestant[0].setVoteScored(9, 3);
contestant[0].setVoteScored(9, 4);
contestant[1].setVoteScored(7, 0);
contestant[1].setVoteScored(10, 1);
contestant[1].setVoteScored(5, 2);
contestant[1].setVoteScored(6, 3);
contestant[1].setVoteScored(7, 4);
contestant[2].setVoteScored(4, 0);
contestant[2].setVoteScored(8, 1);
contestant[2].setVoteScored(6, 2);
contestant[2].setVoteScored(7, 3);
contestant[2].setVoteScored(8, 4);
contestant[3].setVoteScored(6, 0);
contestant[3].setVoteScored(7, 1);
contestant[3].setVoteScored(9, 2);
contestant[3].setVoteScored(8, 3);
contestant[3].setVoteScored(10, 4);
}//end of add_ConstantVote
如果你知道如何设置setVoteScored方法的第一个参数,那么这个例子可能会对你有所帮助。一个用于常量数组,另一个用于内部使用。例如
int[][] values = new int[4][4];
// Assign three elements within it.
values[0][0] = 1;
values[0][1] = 2;
values[0][2] = 3;
for (int i = 0; i < 4; ++i) {
for(int j = 0; j < 4; ++j) {
contestant[i].setVoteScored(values[i][j], j);
}
}