12345678各取一个满足4个等式
2015-08-31 09:23
260 查看
/** * ()+()=7 ()+()=9 ()-()=1 ()-()=2 */ @Test public void testStr() throws Exception{ String str = ""; String temp=""; for (int i=1;i<=8;i++) { for (int j=1;j<=8;j++) { temp=""+i; temp+=j; if(i+j==7) { if(str.length()>0) { str=""; } str+=temp; System.out.print("等于7的等式为:"+i + "+" + j + "=" + (i + j) + " "); for (int k=1;k<=8;k++){ for (int l=1;l<=8;l++){ temp=""+k; temp+=l; if(k+l==9&&str.indexOf(""+k)==-1&&str.indexOf(""+l)==-1) { if(str.length()>2) { str=str.substring(0,2); } str+=temp; System.out.print("等于9的等式为:"+k + "+" + l + "=" + (k + l) + " "); for (int m=1;m<=8;m++){ for (int n=1;n<=8;n++){ temp=""+m; temp+=n; if(m-n==1&&str.indexOf(""+m)==-1&&str.indexOf(""+n)==-1) { if(str.length()>4) { str=str.substring(0,4); } System.out.print("等于1的等式为:"+m + "-" + n + "=" + (m - n) + " "); str+=temp; for (int o=1;o<=8;o++){ for (int p=1;p<=8;p++){ temp=""+o; temp+=p; if(o-p==2&&str.indexOf(""+o)==-1&&str.indexOf(""+p)==-1) { if(str.length()>6) { str=str.substring(0,6); } System.out.print("等于2的等式为:"+o + "-" + p + "=" + (o - p) + " "); str+=temp; }else { continue; } } } }else { continue; } } } System.out.println(); }else { continue; } } } System.out.println(); }else{ str=""; continue; } } } System.out.println(str); }
执行结果:
等于7的等式为:1+6=7 等于9的等式为:2+7=9 等于1的等式为:4-3=1
等于7的等式为:2+5=7 等于9的等式为:1+8=9 等于1的等式为:4-3=1 等于1的等式为:7-6=1
等于7的等式为:3+4=7 等于9的等式为:1+8=9 等于1的等式为:6-5=1
等于9的等式为:2+7=9 等于1的等式为:6-5=1
等于9的等式为:8+1=9 等于1的等式为:6-5=1
等于7的等式为:4+3=7 等于9的等式为:1+8=9 等于1的等式为:6-5=1
等于9的等式为:2+7=9 等于1的等式为:6-5=1
等于9的等式为:8+1=9 等于1的等式为:6-5=1
等于7的等式为:5+2=7 等于9的等式为:1+8=9 等于1的等式为:4-3=1 等于1的等式为:7-6=1
等于7的等式为:6+1=7 等于9的等式为:2+7=9 等于1的等式为:4-3=1
相关文章推荐
- vs2012装qt5.5
- Android中XML解析之XMLSAXParser解析
- (int&) 与int(&)
- 【js】弹出文件选择框,可用与文件上传(适配所有浏览器)
- Python 列表学习与使用
- 使用 Sonar 进行代码质量管理
- 串口RTS, CTS的困惑
- ISO18000-6B和ISO18000-6C(EPC C1G2)标准的区别
- social emotion computing-感情的分类
- 属性
- 20140517随感
- C、C++基础知识一
- uval 6425 Intercity
- CentOS 7 上面的samba共享有问题
- Cheatsheet: 2015 08.01 ~ 08.31
- 使用操作系统命令来trace监听
- Leetcode # 169 Majority Element
- java中四种引用类型
- XML 元素 http://blog.csdn.net/chaiyu2002/article/details/5967186
- 互联网十三五规划出台在即 信息基础建设可望撬动投资两万亿