Java升序排序
public class sortnumstring {//定義sortumstring方法public static String[]sortnumstr(String numStr){//定義壹個類,用string [] (array)作為返回值和參數(String numStr)。If (numStr = = null || numstr.trim()。equals(" ")//如果判斷如果numstr為null,則返回null;//只返回空字符串標記器MTO ken = new string tokenizer(numstr);//定義變量string[]result = new string[m token。count tokens()];//實例化壹個變量並將其賦給壹個數組。int I = 0;//定義I while (mtoken。hasmoretokens()){//執行while循環結果[I]= mtoken . nexttoken();//從I開始的數組中取值i++,即0;//每取出壹個值就加+1得到下壹個值}返回結果;//返回這組值} public static void main(string[]args){//main方法string[]s = sortnumstr(" 99 345 8 888 550-9999 30 ");//將int[] ii = new int[s.length]賦給該數組;//用String[]結果數組定義數組ii的個數for(int I = 0;我& lt二.長度;I++ ){//為循環定義I,I小於int[] ii數組的長度,i++ ii[i] = Integer.parseInt(s[i])每循環壹次自動增加壹次;//給int[]賦值並強制轉換為Integer type } arrays . sort(ii);//排序指定的數字//ASC for(int I = 0;我& lt二.長度;I++){//循環輸出int[] ii數組的值if(I >;0){//If I & gt;0 system . out . print(" ");//然後輸出" " } system . out . print(ii[I]);//否則輸出int[]ii array }/*//desc for(int I = s . length-1;我& gt=0;I-){ if(I & lt;s . length-1){ system . out . print(" ");} system . out . print(ii[I]);}*/ } }