zoukankan      html  css  js  c++  java
  • java实现取字母组成串

    ** 取字母组成串**

    A B C D中取5次,每个字母都可以重复取出,形成一个串。
    现在要求,串中A出现的次数必须为偶数(0次也算偶数)。
    求可以形成多少种可能的串。

    参考答案:
    528

    public class Main1 {
        
        public static boolean judge(int[] A) {
            int count = 0;
            for(int i = 0;i < A.length;i++) {
                if(A[i] == 1)
                    count++;
            }
            if(count == 0 || count % 2 == 0)
                return true;
            return false;
        }
        
        public static void main(String[] args) {
            int[] A = {1,2,3,4};  //1234分别代表ABCD
            int[] tempA = new int[5];
            int count = 0;
            for(int a = 0;a < 4;a++) {
                tempA[0] = A[a];
                for(int b = 0;b < 4;b++) {
                    tempA[1] = A[b];
                    for(int c = 0;c < 4;c++) {
                        tempA[2] = A[c];
                        for(int d = 0;d < 4;d++) {
                            tempA[3] = A[d];
                            for(int e = 0;e < 4;e++) {
                                tempA[4] = A[e];
                                if(judge(tempA))
                                    count++;
                            }
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
    
  • 相关阅读:
    博客园项目
    social-auth-app-django模块
    win10安装软件被阻止后
    expdp和impdp的用法
    EXPDP
    oracle常用的数据迁移方法
    使用spool导出数据
    无法创建spool文件
    sqlldr导入数据
    cmd 登录oracle
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13077035.html
Copyright © 2011-2022 走看看