私はJavaを初めて使用し、以下のロジックを誰かが手伝ってくれるかどうか疑問に思っていました。やろうとしているのは、リストを繰り返し処理し、各リスト要素を配列に格納することです。それが終わったら、配列要素で正解を確認したいと思います。たとえば、3,2,1と入力すると、最終スコアは3になります。コードは次のとおりです。
コード
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!
}
}
どうもありがとう!