package basic.day11; import java.util.Scanner; import java.util.Arrays; public class Demo8 { public static void main(String[] args){ //^\s*[a-dA-D]([,\s]\s*[a-dA-D]){0,3}$ Scanner in =new Scanner(System.in); String answer; while(true){ System.out.println("请输入:"); answer=in.nextLine(); if(answer.matches("^\\s*[a-dA-D]([,\\s]\\s*[a-dA-D]){0,3}$")){ break; }else{ System.out.println("输入有错误,重新输入!"); } } String[] data=answer.trim().toUpperCase().split("[,\\s]\\s*"); Arrays.sort(data); System.out.println(Arrays.toString(data)); } }