List an Array of Strings in alphabetical order

前端 未结 11 1457
独厮守ぢ
独厮守ぢ 2020-12-28 14:49

I have a program which has the user inputs a list of names. I have a switch case going to a function which I would like to have the names print off in alphabetical order.

11条回答
  •  半阙折子戏
    2020-12-28 15:07

    **//With the help of this code u not just sort the arrays in alphabetical order but also can take string from user or console or keyboard
    
    import java.util.Scanner;
    import java.util.Arrays;
    public class ReadName
    {
    final static int ARRAY_ELEMENTS = 3;
    public static void main(String[] args)
    {
    String[] theNames = new String[5];
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Enter the names: ");
    for (int i=0;i

提交回复
热议问题