现在的位置: 首页 > 综合 > 正文

双色球Java模拟

2014年02月10日 ⁄ 综合 ⁄ 共 3113字 ⁄ 字号 评论关闭

package com.jason;

import java.util.ArrayList;

public class RandNum {

        public static ArrayList red;

        public static void main(String[] args)

                              {

                                              int iRed, iBlue;

                                              int iLength;

                                              boolean isRepeat = false;

                                              red = new ArrayList();

                                              System.out.println("生成随机数:");

                                              iRed = 1+(int)(Math.random()*33);

                                              red.add(iRed);

                                              for (int i = 0; ; i++)

                                              {

                                                       iRed = 1+(int)(Math.random()*33);

                                                       iLength = red.size();

                                                       if(6 == iLength)

                                                       {

                                                                break;

                                                        }

                                                        else

                                                        {

                                                              for(int j=0; j<iLength; j++)
                                                              {
                                                                   if(iRed != red.get(j))
                                                                   {
                                                                        isRepeat = false;
                                                                        continue;
                                                                    }
                                                                    else
                                                                    {
                                                                         isRepeat = true;
                                                                         break;
                                                                     }
                                                                  }
                                                                  if(false ==isRepeat)
                                                                  {
                                                                       red.add(iRed);
                                                                   }
                                                           }
  
                                                      }
                            System.out.println("红色球:");
                            for(int i=0; i<iLength; i++)
                           {
                                System.out.print(red.get(i)+" ");
                            }
                            System.out.println();
                            System.out.println("蓝色球:");
                            iBlue = 1+(int)(Math.random()*16);
                            System.out.print(iBlue);
                            }
}

抱歉!评论已关闭.