【发布时间】:2012-04-05 11:48:37
【问题描述】:
我应该编写一个算法,从给定的单词集中整理出字谜。到目前为止,我得到了这个
package Tutorial5;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Anagrams {
/**
* @param args
*/
public static void main(String[] args) {
try{
FileInputStream fis = new FileInputStream("src/Tutorial5/words"); //locate and open the txt.file
DataInputStream dis = new DataInputStream(fis); //get the words from the txt.file
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
String SLine;
while ((SLine = br.readLine()) != null) //read the txt.file line by line
{
System.out.println(SLine); //print out the words
}
dis.close(); //close the DataInputStream
}
catch (Exception e) //see if there is any exception to catch
{
System.err.println("Error: " + e.getMessage());
}
}
}
谁能帮帮我?我在分类部分苦苦挣扎。我不知道如何使用我得到的这段代码并将其转换为字符串并将其排序为字谜。
【问题讨论】:
-
您的输入究竟包含什么?每行只有一个单词,或者已经有一些你只需要排序的字谜。还是您必须从输入的单词中构建字谜?您必须更加精确才能获得建设性的答案。
标签: java