Title Description: Write a program that sorts the characters in the input string according to the following rules.
Rule 1: English letters are arranged from A to Z, and are not case sensitive.
For example, input: type output: Epty
Rule 2: When the case of the same English letter exists, it is arranged in the order of entry.
For example, input: BabA output: aABb
Rule 3: Other characters of non-English letters remain in their original position.
For example, input: By?e output: Be?y
Examples:
Input:
A Famous Saying:much Ado About Nothing (2012/8).
Output:
A aaaabc Dfgghh:iimm nNn oooos sttuuuy (2012/8).
Idea: a nested loop to sort the letters in the string, put all the sorted letters in the temp[], the last output, traversing the original character array, if one is a letter, then go to the temp in the corresponding position has been sorted alphabetically output, non-letter, the output of the original position character.
1 /*Title Description: Write a program that sorts the characters in the input string according to the following rules. 2 Rule 1: English letters are arranged from A to Z, and are not case sensitive. 3 For example, input: type output: Epty4 Rule 2: When the case of the same English letter exists, it is arranged in the order of entry. 5 For example, input: BabA output: AABb6 Rule 3: Other characters of non-English letters remain in their original position. 7 For example, input: By?e output: Be?y8 Examples:9 Input:Ten A Famous Saying:much Ado About Nothing (2012/8). One Output: A A aaaabc Dfgghh:iimm nNn oooos sttuuuy (2012/8). - */ - ImportJava.util.Scanner; the - Public classMain { - - Public Static voidMain (string[] args) { + //TODO auto-generated Method Stub -Scanner in =NewScanner (system.in); + while(In.hasnext ()) A { atString input =in.nextline (); - intLength =input.length (); - Char[] Array =Input.tochararray (); - //all alphabetical sort in input - Char[] temp =New Char[length]; - intK = 0; in for(inti = 0; i<26; i++) - { to for(intj = 0; j<length; J + +) + { - if(Array[j]-' a ' = = I | | array[j]-' a ' = =i) the { *temp[k++] =Array[j]; $ }Panax Notoginseng } - } the //notice!! +K = 0; A for(inti = 0; i<length; i++) the { + if(Array[i] >= ' A ' && array[i] <= ' z ' | | array[i] >= ' A ' && array[i] <= ' z ') - { $Array[i] = temp[k++]; $ //Array[i] = temp[i]; - } - } the System.out.println (string.valueof (array)); - }Wuyi } the -}
36: String Sort sortstring