Я пытаюсь читать из 2-мерных массивов. Что делает этот код, так это то, что он сначала хранит содержимое файла .txt в 2d массивах, по одной строке на элемент. Затем он сравнивает вход пользователя с каждым массивом, ища сходства. Любое сходство будет сохранено в другом массиве.Чтение строк из 2-мерных массивов
Дело в том, что часть сравнения не работает. Любые подсказки о том, почему?
Спасибо.
import java.awt.Point;
import java.io.File;
import java.util.Arrays;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
static int RowCheck =0;
static int C_Row = 0;
static int S_Row = 0;
static String lexicon[][] = new String[3000][10];
static String results[][] = new String[100][10];
private static String find2DIndex(Object[][] array, Object search) {
if (search == null || array == null) return null;
for (int rowIndex = 0; rowIndex < array.length; rowIndex++) {
Object[] row = array[rowIndex];
if (row != null) {
for (int columnIndex = 0; columnIndex < 2; columnIndex++) {
if (search.equals(row[columnIndex])) {
for(int i=0; i<2; i++)
for(int j=0; j<=10; j++)
lexicon[i][j]=results[i][j];
return Arrays.deepToString(results);
}
}
}
}
return null; // value not found in array
}
public static void main(String[] args) throws FileNotFoundException {
File testlex = new File("C:\\Users\\Harry\\Documents\\testlex.txt");
File testlex2 = new File("C:\\Users\\Harry\\Documents\\textlex2.txt");
Scanner cc = new Scanner(testlex2);
Scanner sc = new Scanner(testlex);
while (sc.hasNextLine()){
int column = 0;
String line = sc.nextLine();
sc.useDelimiter("/ *");
if (line.isEmpty())
continue;
C_Row = C_Row + 1;
column = 0;
String[] tokens = line.split("\\s");
for (String token : tokens) {
if (token.isEmpty())
continue;
lexicon[C_Row][column] = token;
column++;
}
}
while (cc.hasNextLine()){
int column = 0;
String line = cc.nextLine();
cc.useDelimiter("/ *");
if (line.isEmpty())
continue;
S_Row = S_Row + 1;
column = 0;
String[] tokens = line.split("\\s");
for (String token : tokens) {
if (token.isEmpty())
continue;
lexicon[S_Row][column] = token;
column++;
}
}
sc.close();
cc.close();
find2DIndex(lexicon, "abash");
System.out.println(C_Row);
}
}