词:测试文件
我正在为我的学校设置一个程序,但我遇到了麻烦。你能帮我找到一种方法来打印打印的单词前后的空格吗?
public class Main {
public static void main(String[] args) {
System.out.println("crossword generator ver. 1.0");
File wordlist = new File("words.txt");
try {
Scanner s = new Scanner(wordlist);
String words[] = new String[1000000];
int lineNr = 0;
while (s.hasNext() && lineNr < 1000000) {
words[lineNr] = s.nextLine();
lineNr++;
}
System.out.println("Wordlist succesfully loaded");
Random r = new Random();
String solution = words[r.nextInt(lineNr)];
System.out.println("Solution = " + solution);
for (int i = 0; i<solution.length(); i++){
char c = solution.charAt(i);
String word;
do{
word = words[r.nextInt(lineNr)];
} while(word.indexOf(c) == -1);
System.out.printf("(%c): %s \n", c ,word);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
}
}