字符串排序冒泡法

tech2024-09-30  17

字符串排序冒泡法

public static void main(String[] args) { // TODO Auto-generated method stub // a1b2c3d4c5 String str = "a1b2c3d4c5"; char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { for (int j = i + 1; j < chars.length; j++) { if (chars[i] > chars[j]) { char temp = chars[i]; chars[i] = chars[j]; chars[j] = temp; } } } System.out.println((int)chars[5]); }
最新回复(0)