首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

各位大侠帮小弟我解决这道超级简单的有关问题(冒泡排序的)

2012-05-06 
各位大侠帮我解决这道超级简单的问题(冒泡排序的)从控制端舒服一个字符串 比如 4848adecb然后排序后输出结

各位大侠帮我解决这道超级简单的问题(冒泡排序的)
从控制端舒服一个字符串 比如 4848adecb 然后排序后输出结果为4488abcde.

[解决办法]
public static void main(String[] args) {
String values = "4848adecb";
char[] chars = new char[values.length()];
for (int i = 0; i < chars.length; i++) {
chars[i] = values.charAt(i);
}
Arrays.sort(chars);
String value = new String(chars);
System.out.println(value);
}
[解决办法]

探讨

public static void main(String[] args) {
String values = "4848adecb";
char[] chars = new char[values.length()];
for (int i = 0; i < chars.length; i++) {
chars[i] = values.charAt(i);
}
Arrays.so……

[解决办法]
Java code
public static String bubbleSort(String str){        char[] chars = new char[str.length()];        for(int i = 0 ; i < str.length() ; i++){            chars[i] = str.charAt(i);        }        for(int i = 0 ; i < chars.length ; i++){            for(int j = i + 1 ; j < chars.length ; j ++){                char temp;                if(chars[i] > chars[j]){                    temp = chars[i];                    chars[i] = chars[j];                    chars[j] = temp;                }            }        }        String retStr = "";        for(int i = 0 ; i < chars.length ; i ++){            retStr += chars[i];        }        return retStr;    }
[解决办法]
LZ这个是完整版的
Java code
public class BubbleSortTest {    public static String bubbleSort(String str){        char[] chars = new char[str.length()];        for(int i = 0 ; i < str.length() ; i++){            chars[i] = str.charAt(i);        }        for(int i = 0 ; i < chars.length ; i++){            for(int j = i + 1 ; j < chars.length ; j ++){                char temp;                if(chars[i] > chars[j]){                    temp = chars[i];                    chars[i] = chars[j];                    chars[j] = temp;                }            }        }        String retStr = "";        for(int i = 0 ; i < chars.length ; i ++){            retStr += chars[i];        }        return retStr;    }        public static void main(String[] args) {        System.out.println(bubbleSort(args.length > 0 ? args[0] : "kief351"));//如果控制端没有输入字符串就默认传一个    }}
[解决办法]
探讨

LZ这个是完整版的
Java code
public class BubbleSortTest {

public static String bubbleSort(String str){
char[] chars = new char[str.length()];
for(int i = 0 ; i < str.length() ; i++){
……

热点排行