Loading...

java .net

2007年6月6日 星期三

==============Fucai.java====================

import java.util.Arrays;
public class Fucai {

private Integer[] redBall;

public Fucai()
{
   redBall = new Integer[33];
   for(int i = 0;i < 33;i++)
   {
    redBall[i] = i+1;
   }

}

public int[] getRedBallArray()
{
   int[] redBallArray = new int[6];

   for(int i = 0;i < 6;i++)
   {
    int temp;
    int index = (int)(Math.random()*(33-1-i));
    redBallArray[i] = redBall[index];
    temp = redBall[index];
    redBall[index] = redBall[33-1-i];
    redBall[33-1-i] = temp;
    //System.out.println(index);
   }
   return redBallArray;
}

public int getBlueBall()
{
   return (int)(Math.random()*(16));
}

public static void main(String[] args)
{
   Fucai fucai = new Fucai();
   int[] redBallArray = fucai.getRedBallArray();
   Arrays.sort(redBallArray);
   System.out.print("红球:");
   for(int i = 0;i < redBallArray.length;i++)
   {
    String numStr = redBallArray[i] + "";
    if(redBallArray[i]<10)
     numStr = "0" + redBallArray[i];
    System.out.print(numStr+",");
   }
   System.out.print("篮球:"+ fucai.getBlueBall());
   System.out.println();
   System.out.println("祝你好运!!!");
}
}

================Fucai.cs===================

using System;
using System.Collections.Generic;
using System.Text;


namespace FucaiApp
{
     class Fucai
     {
         private int[] redBall;

         public Fucai()
         {
             redBall = new int[33];
             for (int i = 0; i < 33; i++)
             {
                 redBall[i] = i + 1;
             }

         }

         public String[] getRedBallArray()
         {
             int[] redBallArray = new int[6];

             for (int i = 0; i < 6; i++)
             {
                 int temp;
                 int index = new System.Random().Next(33 - 1 - i);
                 redBallArray[i] = redBall[index];
                 temp = redBall[index];
                 redBall[index] = redBall[33 - 1 - i];
                 redBall[33 - 1 - i] = temp;
             }
             System.Array.Sort(redBallArray);

             String[] redStr = new String[6];
             for (int i = 0; i < redBallArray.Length; i++)
             {
                 String numStr = redBallArray[i] + "";
                 if (redBallArray[i] < 10)
                     numStr = "0" + redBallArray[i];
                 redStr[i] = numStr;
             }
             return redStr;
         }

         public String getBlueBall()
         {
             int blue = new System.Random().Next(1,16);
             if (blue < 10)
                 return "0" + blue.ToString();
             else
                 return blue.ToString();
         }
     }
}

posted on 2008-08-26 22:06 阅读(83) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

公告

希望有一天

我能用鼠标双击我的钱包

然后选中一张100元

按住“ctrl+c”

接着不停的“ctrl+v”

嘻嘻~~~笑醒~~~



导航

<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

统计

常用链接

留言簿(6)

随笔分类(102)

随笔档案(398)

文章分类

文章档案(10)

有趣网络

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜