0

到目前为止我的编码

我应该从文件中读取一个单词搜索谜题我的问题是它在谜题中只产生“我”。我不知道如何根据文件规范正确格式化单词拼图。拼图的格式通常是这样的:
6 6
devolg
redphk
qchzjc
poaafo
vammnl
qtfoxb
同时该文件可以给我一个不同大小的单词搜索拼图 public static char[][] fill(){ // 创建了 2 个不同的扫描仪一个用于用户输入,一个用于读取文件

    Scanner file1 = new Scanner(System.in);
    // created a count to add the keywords
    int count = 0;

    //System.out.print("Please enter a keyword to search for.");
    // Asking user to input a valid file name
    System.out.print("Please enter a valid puzzle file name\nYou will be asked for the same file name again later.");
    String wordFile = file1.nextLine();
    FileReader infile;
    boolean validFile = false;
    // Creating a while loop that will keep asking for a valid file name
    while(!validFile) {
        // Using a try and catch to obtain correct file
        try {
            infile = new FileReader(wordFile);
            file1 = new Scanner(infile);
            validFile = true;
        }
        //ask the user to put a valid file name if they are wrong
        catch(IOException e) {
            System.out.println("Not a valid file name, please enter again!");
            wordFile = file1.nextLine();
        }
    }


    String numbers = file1.nextLine();
    String[] fileArray = numbers.trim().split(" ");

    int rows = Integer.parseInt(fileArray[0]);
    int columns = Integer.parseInt(fileArray[1]);

    char[][] fillThemLetters = new char [rows][columns];


    String letters = file1.nextLine().trim().replace(" ", "");

    char [] condensed =  letters.toCharArray(); 

    for (int i = 0; i < condensed.length; i++) {

        for(int row = 0; row < rows; row++){


            for(int column = 0; column < columns; column++)
            {
                char index = condensed[i];
                fillThemLetters[row][column] = index;

            }
        }

    }   
    return fillThemLetters;
}
4

0 回答 0