Я делаю быструю игру, и наткнулся на IndexOutOfBoundsException
и задавался вопросом, почему. Я не вижу проблемы/как эта ошибка возникла.IndexOutOfBounds error, hangman game
Это происходит на этой линии:
array[index]+=c;
Любая обратная связь приветствуется.
import java.io.IOException;
import java.util.Scanner;
public class Driver {
public static void main(String[]args) throws IOException {
Scanner console = new Scanner (System.in);
String[] phrase={"television"};
String[] array= new String[phrase.length];
int body =6;
while(array!=phrase) {
char c=(char)System.in.read();
int index= console.nextInt();
array[index]+=c;
if(array[index].charAt(index)==phrase[index].charAt(index)){
System.out.println("the new array");
}
}
}
}
@Jens он здесь заявил: 'INT индекс = console.nextInt(); ', вопрос в том, что представляет собой вход. –
Пожалуйста, отредактируйте свое сообщение и включите полную трассировку стека. –
@Ori Lentz Что значит? –