私は、ユーザー入力を介して値を文字列配列に入力しようとしています。後でこのクラスでもっとやっていきたいですが、配列がいっぱいになっていることを確認して印刷したいだけです。私は特定の値を満たすためにwhileループを使用していますが、ユーザーが0を入力して停止するのを待っていますが、配列のサイズやループの値に関係なく、ArrayIndexOutOfBoundsExceptionが発生します。 0を入力してもそれを停止しません。以下の完全なコード。文字列配列は常にスローArrayIndexOutOfBoundsException
また、例外はそれに関連付けられている私の配列のサイズを持っている(この場合、25)
ヘルプは非常に感謝、感謝することでしょう!
import java.util.Scanner;
public class Dincision {
static Scanner scanner = new Scanner(System.in);
public static String entered;
public static String[]foods;
public static void main (String[]args){
getChoices();
int count=0;
for (count=0; count<=24; count++){
System.out.println(foods[count]);
}
}
static public void getChoices() {
int i=0;
foods= new String[25];
String input;
System.out.println("Enter an eating option.");
input=scanner.next();
while (input != "0"){
foods[i]=input; //error here//
i++;
}
System.out.println("That's all!");
}
}
'while(input!= "0" && i <25){'。 –
また、障害箇所にブレークポイントを追加してデバッグすることもできます。それが自分の学習方法です。 – JonyD
コーヒーが必要ですが、['=='や '!='を使ってJavaの文字列を比較することはできません](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java ) – azurefrog