https://drive.google.com/a/navasotaisd.org/file/d/0B3eMFMufj6uVaVNpR0JYNnV4OTQ/view
好的,所以上面的问题要求您读入一个包含消息的文件,并使用 x, y 坐标系,找到正在读入的字符并打印出该索引值的字符。老实说,我已经尝试了多种解决方案,包括制作数组列表、数组列表的数组列表以及许多其他失败的数据结构。我需要知道的是,如何阅读消息以便我可以搜索它?
File f = new File("cipher.in");
f.createNewFile();
Scanner scan = new Scanner(f);
int numOfLines = scan.nextInt();
scan.nextLine();
ArrayList<Character> list = new ArrayList();
String code = "";
for (int i = 0; i < numOfLines; i++) {
code = scan.nextLine();
for (int j = 0; j < code.length(); j++) {
list.add(code.charAt(j));
}
}
int index = 0;
char[][] matrix = new char[(int)(list.size())][(int)(list.size())];
for (int r = 0; r < matrix.length; r++) {
for (int c = 0; c < matrix[r].length; c++) {
matrix[r][c] = list.get(index);
index++;
if(index>=list.size())
index--;
}
}
抱歉,如果这个问题有点长。为了我的类(class),我需要把这个问题交上去,这样才能在成绩册上得到 100 分。我只是完全陷入困境和沮丧。
最佳答案
尝试使用哈希表来存储数据。您稍后可以搜索它。
关于java - 找出读入数据的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28978669/