⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise7_11.java

📁 java程序设计导论(daniel liang著) 所有偶数课后习题答案
💻 JAVA
字号:
public class Exercise7_11 {  public static void main(String args[]) {    System.out.println(sort("abcABDs"));  }  public static String sort(String s) {    StringBuffer buffer = new StringBuffer(s);    char currentMax;    int currentMaxIndex;    for (int i=buffer.length() - 1; i >= 1; i--) {      // Find the maximum in the buffer[0..i]      currentMax = buffer.charAt(i);      currentMaxIndex = i;      for (int j = i - 1; j >= 0; j--) {        if (currentMax < buffer.charAt(j)) {          currentMax = buffer.charAt(j);          currentMaxIndex = j;        }      }      // Swap buffer.charAt(i) with buffer[currentMaxIndex] if necessary;      if (currentMaxIndex != i) {        buffer.setCharAt(currentMaxIndex, buffer.charAt(i));        buffer.setCharAt(i, currentMax);      }    }    return buffer.toString();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -