java - 找出读入数据的正确方法

标签 java arrays arraylist message coordinate-systems

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/

相关文章:

Java - 二叉搜索树有一个 iterator() 方法,难以实现

java - spring boot jdbc 连接

java - Model 1 是 MVC 架构的子类吗?

arrays - 如何在不使用循环的情况下按每个组的结束索引拆分向量?

java - Hibernate Validator 6.0.8 jar 导致异常

java - 通用静态数组声明

Ruby Hash - 按值排序和打印键

java - 性能循环 arrayList 与 POJO (JAVA)

java - 从数组列表中安全地删除数据

Java休息服务器: avoid the removal of an item while processing it