Java SE


# Java SE #

***

##每一个java程序员的第一个源代码  #
    class a{
    public static void main(String[] args){
    System.out.println("helloword!");
        }
    }


## 字符串大写字母排序 ##
输入一串字符串分别统计各大写字母出现的次数,并按照字母出现的多少输出
>(先输出出现次数多的,次数相同的按字母顺序输出,不出现的字母不输出)

    import java.util.*;
    class a{
        static char[] arr=new char[0];//存 大写字母字符
        static int[] num=new int[0];//存 相对应大写字母字符出现的次数
        public static void main(String[] args){
            String s="Hello My Name Is Ez ,Nice To Meet You Too!,I'm Fine Thank You And You?";
            statis(s);//遍历字符串 查找大写字母!
            print();//打印
        /*
        [H, M, N, I, E, T, Y, F, A]
        [1, 2, 2, 2, 1, 3, 3, 1, 1]
        先按照次数排一遍
        */
            insertSort();//按照次数排序
        /*
        [T, Y, M, N, I, H, E, F, A]
        [3, 3, 2, 2, 2, 1, 1, 1, 1]
        */
            print();
            char[][] cs=new char[][]{};//一个空的二维数组 
            System.out.println(Arrays.toString(cs));
            int temp=0;
            int k=-1;//0 1 2 用于标记二维数组中的哪一个数组
            for(int i=0;i<num.length;i++{       
                if(num[i]!=temp){
                    char[] c=new char[1];
                    c[0]=arr[i];
                    cs=Arrays.copyOf(cs,cs.length+1);
                    cs[cs.length-1]=c;
                    temp=num[i];
                    k=k+1;
                }else{
                    char[] c=cs[k];
                    c=Arrays.copyOf(c,c.length+1);
                    c[c.length-1]=arr[i];
                    cs[k]=c;
                }
            }    
            /*
            cs[][]=
            [T, Y]
            [M, N, I]
            [H, E, F, A]
            */
        
            for(int i=0;i<cs.length;i++){
                charSort(cs[i]);
                System.out.println(Arrays.toString(cs[i]));
            }
        /*
        [T, Y]
        [I, M, N]
        [A, E, F, H]
        */
        
            for(int i=0;i<cs.length;i++){
                for(int j=0;j<cs[i].length;j++){
                    System.out.print(cs[i][j]+"\t");
                }
            }
            System.out.println();
            for(int i=0;i<num.length;i++){
                System.out.print(num[i]+"\t");
            }
        
        }
        public static void charSort(char[] c){
            for(int i=1;i<c.length;i++){
                char e=c[i];
                int j;
                for(j=i;j>0&&c[j-1]>e;j--){
                    c[j]=c[j-1];
                }
                c[j]=e;
            }
        }

        public static void insertSort(){
            for(int i=1;i<num.length;i++){
                int e=num[i];
                char ec=arr[i];
                int j;
                for(j=i;j>0&&num[j-1]<e;j--){
                    num[j]=num[j-1];
                    arr[j]=arr[j-1];
                }
                num[j]=e;
                arr[j]=ec;
            }
        }
        public static void print(){
            System.out.println(Arrays.toString(arr));
            System.out.println(Arrays.toString(num));
        }
    //遍历字符串 查找大写字母!
        public static void statis(String s){
            for(int i=0;i<s.length();i++){
                char c=s.charAt(i);//字符串中某个角标对应的字符
                //判断是否是大写字母
                if(c>=65&&c<=90){
                    if(arr.length==0){//第一个直接进 因为数组长度为0
                        arr=Arrays.copyOf(arr,arr.length+1);
                        num=Arrays.copyOf(num,num.length+1);
                        arr[arr.length-1]=c;
                        num[arr.length-1]=1;//进去的同时计数
                    }else{//其他字母需判断 看是否有重复
                        boolean temp=true;//代表加元素
                        for(int j=0;j<arr.length;j++){
                            if(arr[j]==c){
                                num[j]=num[j]+1;
                                temp=false;//当temp=false,下面的if()不再执行
                                break;
                            }
                        }
                        //temp=true表示if()内为真,可以继续执行
                        if(temp){
                            arr=Arrays.copyOf(arr,arr.length+1);
                            num=Arrays.copyOf(num,num.length+1);
                            arr[arr.length-1]=c;
                            num[arr.length-1]=1;
                        }
                    }
                }
            }
        }

    }

! [](https://i.imgur.com/zFadt3M.png)
! [](https://i.imgur.com/iGqljKP.png)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值