for的叠代和穷举

1 //猴子吃桃
2         int a=1;
3         for(int i=6;i>0;i--)
4         {
5             a=(a+1)*2;
6             
7         }
8         System.out.println("a="+a);
View Code

1 //棋盘放粮食
2 double sum = 1;
3         for(int i=1;i<=64;i++)
4             {
5                 sum*=2;
6             }
7         System.out.println("最后一个放的粮食数sum="+sum);
View Code

 1 //加减法
 2         for(int a1=-1;a1<=1;a1+=2)
 3          {
 4             for(int b=-1;b<=1;b+=2)
 5               {
 6                 for(int c=-1;c<=1;c+=2)
 7                     {
 8                     for(int d=-1;d<=1;d+=2)
 9                         {
10                         if(123+a1*45+b*67+c*8+d*9==100)
11                             {               
12                               System.out.println("运算式是:123+("+a1+")x45+("+b+")x67(+"+c+")x8+("+d+")x9=100");
13                             }
14                         }
15                     }
16               }
17          }
View Code

原文地址:https://www.cnblogs.com/beens/p/5222645.html