==============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();
}
}
}
没有评论:
发表评论