java语言编写
发布网友
发布时间:2022-08-04 18:29
我来回答
共4个回答
热心网友
时间:2024-03-24 20:46
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class ww{
public static void main(String[] agrs){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = null;
System.out.print("原字符序列:");
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
String s[]=str.split("\\s+");
Arrays.sort(s);
System.out.print("升序排序后:");
for(int i=0;i<s.length;i++)
{
System.out.print(s[i]+" ");
}
System.out.print("\n逆序输出为:");
for(int i=s.length-1;i>=0;i--)
{
System.out.print(s[i]+" ");
}
}
}
热心网友
时间:2024-03-24 20:46
import java.util.Arrays;
public class StringSort {
public static void main(String[] args){
String str="acvbepfz";
char[] toCharArray = str.toCharArray();
System.out.print("源字符序列:"+" ");
xunHuan(toCharArray);
Arrays.sort(toCharArray);
System.out.println();
System.out.print("升序排序后:"+" ");
xunHuan(toCharArray);
System.out.println();
System.out.print("逆序输出为:"+" ");
for(int i=toCharArray.length-1;i>=0;i--){
System.out.print(toCharArray[i]+" ");
}
}
public static void xunHuan(char[] ars){
for (char newChar : ars) {
System.out.print(newChar+" ");
}
}
}
热心网友
时间:2024-03-24 20:47
import java.util.Arrays;
public class demo {
public static void main(String[] args) {
char[] ch ={'a','c','u','b','e','p','f','z'};
Arrays.sort(ch);
for(int x=ch.length-1;x>=0;x--){
System.out.print(ch[x]+" ");
}
}
}
这样就行了。
热心网友
时间:2024-03-24 20:47
import java.util.Arrays;
public class ArrayOP {
public static void main(String[] args) {
char[] chars = { 'a', 'z', 'k', 'q' };
Arrays.sort(chars);// 排序
System.out.print("\n\n顺序输出:");
for (int index = 0; null != chars && index < chars.length; index++) {
System.out.print(" " + chars[index]);
}
System.out.print("\n\n逆顺序输出:");
for (int index = 0; null != chars && index < chars.length; index++) {
System.out.print(" " + chars[chars.length - index - 1]);
}
}
}