new.programmer
new.programmer

Reputation: 27

How can I make this method with for loop

I tried to writng this code but I think it looks not good :)

Please.. Can I make this method with for loop ? and How?

 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

Upvotes: 0

Views: 48

Answers (1)

Shiladittya Chakraborty
Shiladittya Chakraborty

Reputation: 4418

If you know how to put first parameter of the setVoteScored method then this example may be help you. One for your constant array another for internal use. For example

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);
  }
}

Upvotes: 1

Related Questions