私は、whileループを使用して配列を塗りつぶす作業をしています(JOptionPaneを使用する必要があります)。forループなしの1D配列へのJavaの埋め込み
int score[] = new int [10];
int x = 0;
int size = 0;
x = Integer.parseInt(JOptionPane.showInputDialog("Please enter the score"));
while (x != -1){
score[size]= x ;
x = Integer.parseInt(JOptionPane.showInputDialog("Please enter the score"));
size++;
}
System.out.println(score[0]+score[1]+score[2]+score[3]+score[4]);
}
これは私の現在のコードです.1,2,3,4,5,1を入力すると、printlnの結果は15になります。 私は何をしたのか探してもらえますか?私は新しいJavaユーザーです。
forループと一緒にarray.lengthを使用してください。 –
こちらをご覧ください。 http://stackoverflow.com/questions/576855/how-do-i-fill-arrays-in-java – Redwan
@Redwan私はまだこの質問を見ましたが、回答が見つかりませんでした – hDDen