微軟Java筆試題之按照字母排序

微軟Java筆試題之按照字母排序

深圳達(dá)內(nèi)教育      2022-04-19 15:14:01     10

微軟Java筆試題之按照字母排序,1.對字符串進(jìn)行排序,用任意一種編程語言來實現(xiàn),不能使用現(xiàn)有的類,在排序中,字符串Bc,Ad,aC,Hello,X man,little,During,

課程價格 請咨詢

上課時段: 授課校區(qū):

詳細(xì)介紹

1.對字符串進(jìn)行排序,用任意一種編程語言來實現(xiàn),不能使用現(xiàn)有的類,在排序中,字符串“Bc”,“Ad”,“aC”,“Hello”,“X man”,“little”,“During”,“day”能夠排序成“Ad”,"aC",“Bc”,“During”,“day”,“Hello”,“little”,“Hello”,也就是說,在排序的過程并不是傳統(tǒng)的按照字符串排序,在排序中還需要將小寫字母一并排序,也就是說a字符串要在B或b之前。

import?java.util.Arrays;???import?java.util.Comparator;??????class?T?{?????private?static?final?int?MASK?=?0xFFDF;?//?用來把小寫變成大寫???????public?static?int?compare(String?o1,?String?o2)?{???????int?length1?=?o1.length();???????int?length2?=?o2.length();???????int?length?=?length1?>?length2???length2?:?length1;???????int?c1,?c2;???????int?d1,?d2;???????for?(int?i?=?0;?i?<?length;?i++)?{?????????c1?=?o1.charAt(i);?????????c2?=?o2.charAt(i);?????????d1?=?c1?&?MASK;?????????d2?=?c2?&?MASK;?????????if?(d1?>?d2)?{???????????return?1;?????????}?else?if?(d1?<?d2)?{???????????return?-1;?????????}?else?{???????????if?(c1?>?c2)?{?????????????return?1;???????????}?else?if?(c1?<?c2)?{?????????????return?-1;???????????}?????????}???????}???????if?(length1?>?length2)?{?????????return?1;???????}?else?if?(length1?<?length2)?{?????????return?-1;???????}???????return?0;?????}???????public?static?void?sortByPOPO(String[]?args)?{???????String?tmp;???????for?(int?i?=?0;?i?<?args.length;?i++)?{?????????for?(int?j?=?i?+?1;?j?<?args.length;?j++)?{???????????if?(compare(args[i],?args[j])?>?0)?{?????????????tmp?=?args[i];?????????????args[i]?=?args[j];?????????????args[j]?=?tmp;???????????}?????????}???????}???????//?[Ad,?aC,?Bc,?During,?day,?Hello,?little,?X?man]???????System.out.println(Arrays.toString(args));?????}???????public?static?void?main(String[]?args)?{???????String[]?strs?=?{?"Bc",?"Ad",?"aC",?"Hello",?"X?man",?"little",?"During",???????????"day"?};???????sortByPOPO(strs);???????}???}

以上就是深圳達(dá)內(nèi)教育java培訓(xùn)機構(gòu)的小編針對“微軟Java筆試題之按照字母排序”的內(nèi)容進(jìn)行的回答,希望對大家有所幫助,如有疑問,請在線咨詢,有專業(yè)老師隨時為你服務(wù)。

Java筆試題

培訓(xùn)啦提醒您:交易時請核實對方資質(zhì),對于過大宣傳或承諾需謹(jǐn)慎!任何要求預(yù)付定金、匯款等方式均存在風(fēng)險,謹(jǐn)防上當(dāng)。