intmax= num; intn= charArray.length; //将数组中的元素两两比较 for (inti=0; i < n; i++) { for (intj= i + 1; j < n; j++) { //交换对比最大值 swap(charArray, i, j); //更新最大值 max = Math.max(max, Integer.parseInt(newString(charArray))); //还原 swap(charArray, i, j);
} } return max;
}
publicvoidswap(char[] chars, int i, int j) { chartemp= chars[i]; chars[i] = chars[j]; chars[j] = temp; } }