JAVA程序设计(自主模式)-字符串排序

版权声明:文章都是原创,转载请注明~~~~ https://blog.csdn.net/SourDumplings/article/details/88391817

字符串排序

(100/100 分数)

字符串排序

用Java编写一个能对一组字符串按字典序升序排序的程序 输入为N和N行字符串,需要按行输出字符串升序排序的结果 如输入
3
Abc
Abe
Abd
输出:
Abc
Abd
Abe

Java:


/**
 * @Date    : 2018-04-05 18:08:51
 * @Author  : 酸饺子 ([email protected])
 * @Link    : https://github.com/SourDumplings
 * @Version : $Id$
 *
 * 简单的字符串排序
*/

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int t = cin.nextInt();
        List<String> lists = new ArrayList<String>();
        for (int i = 0; i <= t; i++)
        {
            lists.add(cin.nextLine());
        }
        Collections.sort(lists);
        for (String li : lists)
        {
            System.out.println(li);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/SourDumplings/article/details/88391817