欢迎使用 Typecho

Successfully Installed Typecho

//代码块测试
import java.util.*;
public class Sort1 {
    private static int count;
    private static void BubbleSort(String[] str2,int count1)
    {
        for (int j=0;j<count1;j++) {
            for (int k = 1; k < count1 - j; k++) {
                if (str2[k-1].compareTo(str2[k]) > 0) {
                    String temp = str2[k-1];
                    str2[k-1] = str2[k];
                    str2[k] = temp;
                }
            }
        }
    }

    public static void main(String []args)
    {
        Scanner sc1 = new Scanner(System.in);
        System.out.println("请输入要输入的字符串的数量");
        count=sc1.nextInt();
        String [] str = new String[count+1];
        for (int l=0;l<count;l++)
            str[l] = sc1.next();
        BubbleSort(str,count);
        System.out.println("排序后的字符串为:");
        for (int i=0;i<count;i++)
        {
            System.out.print(str[i]+' ');
        }
    }
}

本文链接:

http://maoookai.cn/index.php/archives/1/
1 + 4 =
1 评论
    1月1日 回复

    欢迎加入 Typecho 大家族