** 取字母组成串**

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);
}
}

最新文章

  1. 利用反射模拟一个spring的内部工作原理
  2. android 8种对话框(Dialog)使用方法汇总
  3. ajax传值方式为数组
  4. (转载)前端构建工具gulp使用
  5. ios 移动应用通用逻辑流程
  6. 如果Android和C#在一起?
  7. cocos2dx 3.1创建工 mac
  8. 关于css中透明度继承的问题
  9. ftp服务器端的安装及配置
  10. Is it possible to run native sql with entity framework?
  11. windows 定时备份linux 上oracle 数据库
  12. 《Mem2Seq: Effectively Incorporating Knowledge Bases into End-to-EndTask-Oriented Dialog Systems》
  13. header 和http状态码
  14. php null
  15. HDU 2058:The sum problem(数学)
  16. 【读书笔记】iOS-网络-理解错误源
  17. 【大数据】SparkStreaming学习笔记
  18. UI设计必用工具 — AI快捷键大全
  19. 允许使用root远程ssh登录(Ubuntu 16.04)
  20. iOS推送证书从申请到使用

热门文章

  1. Mysql常用sql语句(21)- regexp 正则表达式查询
  2. flink流处理从0到1
  3. DevOps vs. Agile:它们有什么共同点?
  4. 黑马程序员_毕向东_Java基础视频教程——位运算练习(随笔)
  5. Docker 部署Spring Boot 项目并连接mysql、redis容器(记录过程)
  6. mysql运维入门1:基础及备份还原
  7. ABAP基础1:概念
  8. 王玉兰201771010128《面象对象程序设计(Java)》第九周学习总结
  9. tp入门
  10. 获取cookie里面的sessionid