一个关于Java中单词排序的问题,谢谢了!

来源:百度知道 编辑:UC知道 时间:2024/06/15 21:34:35
比如this that tape these这三个词,如何像字典一样将它们排成 tape that these this ?

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Scanner;

public class test {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
String b1 = b.readLine();
String[] str =b1.split(" ");
Arrays.sort(str);
int j=str.length/3;
for(int i=0;i<str.length;i++){
System.out.print(str[i].toString()+" ");

}

}

输入几个单词 用空格分开 回车系统排序打印结果

这个程序可以满足你的要求!
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStrea