第1个回答 2013-08-25
来个简单点的,JDK自带的方法
import java.util.Arrays;
public class Test001 {
public static void main(String[] args) {
System.out.println(sort("abACc"));
}
/** 排序 */
public static String sort(String inString){
char[] chars = inString.toCharArray();
Arrays.sort(chars);
return new String(chars);
}
}
第2个回答 2013-08-25
import java.util.Queue;
import java.util.*;
import java.util.Scanner;
public class M {
public static void main(String[] args)
{
String x=new String();
Scanner scanner = new Scanner(System.in);
try {
x = scanner.next();
}catch(java.util.InputMismatchException ime) {
//if the next token does not match the Integer regular
//expression, or is out of range
System.out.println("not a integer");
}
int[] s=new int[x.length()];
for(int i=0;i<x.length();i++)
s[i]=x.charAt(i);
//用冒泡排序法对al数组进行排序,从小到大
for(int i=0;i<10;i++)
for(int j=i+1;j<10;j++)
{
int temp;
if(s[j]<s[i])
{
temp=s[j];s[j]=s[i];s[i]=temp;
}
}
for(int i=0;i<x.length();i++)
{
System.out.print((char) s[i]);
}
}
}
第3个回答 2013-08-25
public class sort(){
public static void main(String args[]){
String s="12345678";
char[] ch = s.toCharArray(s);
StringBuffer sb = new StringBuffer();
for(int i=ch.length()-1;i>=0;i++){
sb.append(ch[i]);
}
}
}
第4个回答 2013-08-25
很简单,字符数组有个sort方法,参数是数组本身,咻的一下就排好了