【发布时间】:2011-10-17 20:52:18
【问题描述】:
我的任务是询问用户他想输入的字符串数量。然后我会提示他纠正琴弦。然后我应该按字母顺序打印刺痛。我完成了大部分任务,只需要一个排序算法,比如冒泡排序来完成它。这是我的代码。
import java.io.*;
public class sorting
{
private static BufferedReader stdin=new BufferedReader(new InputStreamReader( System.in));
public static void main(String[] arguments) throws IOException
{
System.out.println("How many strings would you like to enter?");
int stringCount = Integer.parseInt(stdin.readLine());
String[] stringInput = new String[stringCount];
for(int i = 0; i < stringCount; i++)
{
System.out.print("Could you enter the strings here: ");
stringInput[i] = stdin.readLine();
}
//Now how do i use a sorting algorithm?
}
}
【问题讨论】:
-
en.wikipedia.org/wiki/Bubble_sort。您将对数组进行排序,进行字母字符串比较。您不需要对数组中的字符进行排序,只需对数组中的字符串进行排序即可。
-
[显然有一个未说明的要求,即他不要在“java.util”中使用任何东西。见stackoverflow.com/questions/6917833/…]
标签: java algorithm sorting bubble-sort