package com.dev.base.exercise.oct26;
/**
* @ClassName: Demo
* @Description: TODO
* @Author LHN
* @Date 2019/6/22 20:26
* @Version 1.0.0
*/
public class Demo {
public static void main(String[] args) {
String s = "goodgoodstudydaydayup";
String result = sort(s);
System.out.println(result);
}
public static String sort(String s) {
char[] c = s.toCharArray();
for (int i = 0; i < c.length - 1; i++) {
for (int j = 0; j < c.length - i - 1; j++) {
if(c[j] > c[j+1]) {
char temp = c[j];
c[j] = c[j+1];
c[j+1] = temp;
}
}
}
return new String(c);
}
}
给定一个英文字符串,将字符串按顺序排序
最新推荐文章于 2024-08-30 15:28:52 发布