| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 378 人关注过本帖
标题:怎样使用循环
取消只看楼主 加入收藏
dengjinbao
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:64
专家分:119
注 册:2011-3-22
结帖率:0
收藏
 问题点数:0 回复次数:0 
怎样使用循环
for (i=0;i<4 ;i++ )
                    {
                        if (positionNumber==4)
                        {
                            for ( m=0;m<4 ;m++ )
                            {
                                System.out.print(a[m]);
                            }
                           
                             break;
                        }
                        else if (positionNumber!=4)
                        {
                            //a[i]==temp;
                            if (i==0)
                            {
                                a[i] = randomNumber.nextInt(9)+1;
                                
                                    for (k=0,j=i;k<=m ;k++ )
                                    {
                                        if (a[i]!=b[j][k])
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            for (int n=0; ;n++ )
                                            {
                                                a[i] = randomNumber.nextInt(9)+1;
                                                if (a[i]!=b[j][k])
                                                {
                                                    break;
                                                }
                                            }
                                            
                                            k=-1;
                                        }
                                    }
                                
                              
                            }
                            else if(i!=0)
                            {
                                a[i] = randomNumber.nextInt(10);
                                
                                    for (k=0,j=i;k<=m ;k++ )
                                    {
                                        if (a[i]!=b[j][k])
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            for (int n=0; ;n++ )
                                            {
                                                a[i] = randomNumber.nextInt(10)+1;
                                                if (a[i]!=b[j][k])
                                                {
                                                    break;
                                                }
                                            }
                                            k=-1;
                                        }
                                    }
                                    
                                
                            }
                            for (k=0;k<a.length ;k++ )
                            {
                                 System.out.print(a[k]);
                            }
                            System.out.print("猜对几个数字:");
                            rightNumber = in.nextInt();
                            System.out.print("猜对几个位置:");
                            positionNumber = in.nextInt();
                            if (positionNumber<tempPosition)
                            {
                                positionNumber=tempPosition;
                                
                            }
                           else if (positionNumber>tempPosition)
                           {
                                tempPosition = positionNumber;
                                
                           }
                           else
                          {
                               for (j=0;j<10 ;j++ )
                               {
                                   m=j;
                                   b[i][j]=a[i];
                                   i=i-1;
                                   break;
                               }
                              
                          }
                        //}
                        }
怎样把这段代码优化
2011-03-26 00:02
快速回复:怎样使用循环
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029694 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved