I am new to Java and was wondering if anyone would help me out with the logic below. What am trying to do is to iterate over a list and store each list element into Array. Once that's done, then I want to check the array element for correct answers. So for example 3,2,1 is enter then the final score should be 3. Here is the code.
Code
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
public class IterateOverArray {
public static int SCORE = 0;
static List<Integer> list = new ArrayList<Integer>();
static int[] temp;
public static void main(String[] args) throws Exception {
list.clear();
list.add(3);
list.add(2);
list.add(1);
getScore();
}
public static void getScore() throws RemoteException {
temp = new int[3];
for (Integer value : list) {
for (int i = 0; i < temp.length; i++) {
temp[i] += value.intValue();
}
if (temp[0] == 3) {
SCORE++;
}
if (temp[1] == 2) {
SCORE++;
}
if (temp[2] == 1) {
SCORE++;
}
}
System.out.println("total score: " + SCORE); // Final Score should be 3!
}
}
Many Thanks!