Вы использовали вложенные циклы for
, которые не нужны для вашей проблемы. А также array.length + 1
вызывает исключение. Это должно быть array.length
.
char[] first = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'};
int[] columns = {1, 2, 3, 4, 5, 6, 7, 8};
char[] rows = {'A', 'B', 'C', 'D'};
int[] fourth = {0, 1, 2, 3, 4, 5, 6, 7};
boolean firstTest;
boolean columnTest;
boolean rowsTest;
boolean fourthTest;
if(input.length()==4) {
for (int j = 0; j < first.length; j++){
if (input.charAt(0) == first[j]){
firstTest = true;
break;
}
}
if(!firstTest)
return false;
for (int j = 0; j < columns.length; j++){
if (input.charAt(0) == columns[j]){
columnsTest= true;
break;
}
}
if(!columnTest)
return false;
// Do the same for other tests as well
// if all tests are passed
return true;
}
Если вам нужен более быстрый метод, вы можете использовать Hashset и сэкономить время на зацикливание.
Set<Character> first= new HashSet<>(Arrays.asList('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'));
Set<Integer> columns= new HashSet<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8));
// create other sets
if(first.contains(input.charAt(0)) && columns.contains(input.charAt(1)) && /*other similar checks*/)
return true;
return false;