1. 设定一批整数,使用选择法对其从小到大排序并输出。
2. 编写一个程序,设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符中的小写字符输出。

解决方案 »

  1.   

    第一个:选择法排序
    public class SelectSort {
    public static void main(String[] args)
    {
    int i, j, k, temp;
    int[] a = {2, 4, 8, 12, 3, 21, 19, 45, 36, 15};
    for(i=0;i<10;i++) 

    k=i;  //给记号赋值
    for(j=i+1; j<10; j++) 
           if(a[k]>a[j]) 
            k=j;  //是k总是指向最小元素
           if(i!=k) 
           {   
           //当k!=i是才交换,否则a[i]即为最小
              temp=a[i]; 
              a[i]=a[k]; 
              a[k]=temp; 
           } 

    for(i=0; i<10; i++)
    System.out.println(a[i]);
    }
    }
    -------------------------华丽的分割线---------------------------
    第二个:找出大写和小写字母public class CapitalandSmall { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String test = "AsiaLiuSCSfromTJU";
    String captial = "", small = "";
    int len = test.length();
    for(int i = 0; i < len; i++)
    {
    char c = test.charAt(i);
    if (c >= 'A' && c <= 'Z') 
    captial = captial + c;
     else if (c >= 'a' && c <= 'z') 
        small = small + c;
    }
    System.out.println(captial);
    System.out.println(small);
    }
    }