一数组 {'f','F','K','A','a','j','z'}
要求排序 为 {'A','a','F','f','j','K','z'}

解决方案 »

  1.   


    public int compareTo(char c1, char c2)
    {
    if(Math.abs(c1 - c2) == 32)
    {
    return c2 - c1;
    }

    if(c1 >= 'a' && c1 <='z' )
    {
    c1 = (char)(c1 - 32);
    }

    if(c2 >= 'a' && c2 <='z' )
    {
    c2 = (char)(c2 - 32);
    }

    return c1 - c2;
    }
      

  2.   

    哦, 忘了.第一个if中
    if(Math.abs(c1 - c2) == 32) 
    还要判断 c1和c2在 'a'到'z'以及'A'到'Z'之间
      

  3.   

    public class VA {
    public static void main(String [] args) {
    String [] str = {"a","b","A","e"};
    VA.compositor(str);
    }
    public static void compositor(String [] str){
    String st = "AaBbCcDdEeFfGgKkLlMm";
    String temp = "";
    for(int i=0; i<str.length; i++) {
    for(int b=i; b<str.length; b++) {
    if(st.indexOf(str[i])>st.indexOf(str[b])) {
    temp = str[i];
    str[i] = str[b];
    str[b] = temp;
    }
    }
    }
    for(int i=0; i<str.length; i++) {
    System.out.println(str[i]);
    }
    }
    }
      

  4.   

    package algorithm;public class SpecialSort {
    static char[] array = {'f','F','K','A','a','j','z'};
    //static char[] array = {'F','c'};
    public static void main(String[] args) {
    System.out.println("before sort");
    for(char a : array){
       System.out.print(a+" ");
    }
    System.out.println();
    bubble(array);
    System.out.println("after sort");
    for(char a : array){
       System.out.print(a+" ");
    }
    }
    private static void bubble(char[] array){
    char temp;
    for (int i = 0; i < array.length - 1; i++) {
    for (int j = i + 1; j < array.length; j++) {
    // 左边的数是大写,右边的数是小写
    if (array[i] >= 65 && array[i] <= 90 && array[j] >= 97&& array[j] <= 122) {
    //左边的数是R,右边的数是r/r+,位置不变
    if (array[j] >= array[i] + 32) {
    continue;
    //左边的数是R,右边的数是r-,换位
    } else {
    temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    }
    }
    // 左边的数是小写,右边的数是大写
    else if(array[i] >= 97 && array[i] <= 122 && array[j] >= 65&& array[j] <= 90){
    //左边的数是r,右边的数是R+,位置不变
    if(array[i]<array[j]+32){
    continue;
    }
    //左边的数是r,右边的数是R/R-,换位
    else {
    temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    }
    }
    // 左边和右边的数都是大写或小写
    else {
    if (array[i] > array[j]) {
    temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    }
    }
    }
    }
    }
    }
      

  5.   


    import java.util.Arrays;
    import java.util.Comparator;public class Temp
    {
        public static void main(String args[])
        {
            Character[] chs = {'f', 'F', 'K', 'A', 'a', 'j', 'z'};
            
            Arrays.sort(chs, new Comparator<Character>()
            {
                public int compare(Character c1, Character c2)
                {
                    char ch1 = Character.toUpperCase(c1);
                    char ch2 = Character.toUpperCase(c2);
                    
                    if(ch1 == ch2)
                    {
                        return c1.charValue() - c2.charValue();
                    }
                    else
                    {
                        return ch1 - ch2;
                    }
                }
            });
            
            for(char c: chs)
            {
                System.out.println(c);
            }
        }
    }