java中怎么按字符串中几位排序字符串
展开全部
import java.util.*;
public class CharSort
{
private static Scanner sc=new Scanner(System.in);
private static StringBuffer sb=new StringBuffer();
public static void main(String[] args)
{
System.out.println("\n\t\t==========字符串排序!==========\n");
init();
}//初始化!
private static void init()
{
System.out.println("请输入:");
for (; ; )
{
String a=input();
char[] arr=a.toCharArray();
Arrays.sort(arr);
sb.append(a);
print(arr,sb);
}
}
//扫描!
private static String input()
{
String a=sc.nextLine();
return a;
}
//打印!
private static void print(char[] arr,StringBuffer sb)
{
System.out.println("\n字符串排序演示:");
for (int i=0;i<arr.length ;i++ )
{
System.out.print(arr[i]);
}
System.out.println("\n=====================\n倒序演示:");
System.out.print(sb.reverse());
}
}
public class CharSort
{
private static Scanner sc=new Scanner(System.in);
private static StringBuffer sb=new StringBuffer();
public static void main(String[] args)
{
System.out.println("\n\t\t==========字符串排序!==========\n");
init();
}//初始化!
private static void init()
{
System.out.println("请输入:");
for (; ; )
{
String a=input();
char[] arr=a.toCharArray();
Arrays.sort(arr);
sb.append(a);
print(arr,sb);
}
}
//扫描!
private static String input()
{
String a=sc.nextLine();
return a;
}
//打印!
private static void print(char[] arr,StringBuffer sb)
{
System.out.println("\n字符串排序演示:");
for (int i=0;i<arr.length ;i++ )
{
System.out.print(arr[i]);
}
System.out.println("\n=====================\n倒序演示:");
System.out.print(sb.reverse());
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询