0
내가 게시하려고하는 코드의 일부는 사용자에게 객관식 질문을 요청하는 프로그램에서 온 것입니다. 프로그램은 각 질문에 대한 점수를 유지하고 다른 배열에 저장 될 총계를가집니다. 나는 여러 플레이어가 이것을 연주 할 것이므로, 그래서 나는 2 개의 배열이 필요할 것이다.배열 요소의 합을 더하고 다른 배열에 저장 하시겠습니까? (Java)
//Asks questions and stores score in array
public static int [] questions()
{
userinput=""; //input will be stored in here
int total[]= new int[100];
int score[]=new int[5];
for(int i=0; i < ps.length; i++)
{
userinput=JOptionPane.showInputDialog(que[i]); //Outputs a question stored in another array in another method.
if (response.equals(ans[i])) //this compares the user input to the correct answer of the question, which is in another method.
{
JOptionPane.showMessageDialog(null,"You selected " + " " + ans[i] + " You were correct, 1 point!");
score[i]=1;
total[i]=total[i]+score[i];
}
else if(!response.equals(ans[i])) // If the answer isn't correct
{
score[i]=0; // I want to assign 0 for the question
JOptionPane.showMessageDialog(null,"You're wrong!, The correct answer was "+ans[i]);
}
} // close loop
return total; // return's this to another method which will do all of the other work
}
내가 여기에 문제가있을 것 같다 : 답이 맞다면
JOptionPane.showMessageDialog(null,"You selected " + " " + ans[i] + " You were correct, 1 point!");
score[i]=1;
total[i]=total[i]+score[i];
내가 점수 []의 각 요소에 1을 추가하려면 여기
내가 무엇을 가지고 . 그럼 나는 총 점수 []를 축적하고 전체 []의 각 요소에 그것을 저장하고 싶습니다. 나는 그것을 배열에 저장하는 또 다른 메소드로 전체를 반환한다.
의심스러운 코드는'totalscore [i] ++'와 같습니다. 게다가'totalscore'는 100 개의 elems를 가지지 만'score'는 15 elems를가집니다. 왜? –
죄송합니다. 복사하여 붙여 넣기 오류입니다. 내가 작업하고있는 배열은 score []와 total []뿐입니다. – user1058452
"total []"또는 "score []"이외의 배열이 있으면 무시하십시오! – user1058452