我有一个包含50个不同长度和内容的字符串行的文本文件。我需要阅读文件并按升序排序。 排序条件:我如何通过ķ移动到分拣串线:字数在从字母开始的“a”由Shell排序字符串排序
public static void main(String[] args) throws FileNotFoundException {
String token1 = "";
Scanner inFile1 = new Scanner(new File("E:\\text.txt"));
List<String> temps = new LinkedList<String>();
inFile1.useDelimiter(". ");
while (inFile1.hasNext()) {
token1 = inFile1.nextLine();
temps.add(token1);
}
inFile1.close();
String[] tempsArray = temps.toArray(new String[0]);
for (int i = 0; i < tempsArray.length; i++) {
System.out.println(tempsArray[i]);
}
int cnt = 0; //counts of words in the string line
for (int i=0; i<tempsArray.length; i++) {
int k=0; //counts of words that start from the letter "а"
System.out.println("Line № = " + i);
StringTokenizer st = new StringTokenizer(tempsArray[i]);
while (st.hasMoreTokens()) {
cnt++;
String s= st.nextToken();
if (s.charAt(0)=='a') {
k++;
}
}
System.out.println("Words count = " + cnt);
cnt=0;
System.out.println("Words 'а' = " + k);
}
}
新问题了一句多少?该代码后还应该做些什么?
为什么不给它一个尝试第一,看多远,你可以得到的,根据你了解在Java中不同的数据类型是什么?然后,如果你卡住,发布一个问题。 – ProgrammerDan
我不需要编码方面的帮助。我需要帮助完成这项任务的算法。然后我会尝试为该算法编写代码。 – iFlash