有100个人要抽奖,抽到奖的人员是(3个名额)(这里考虑要没有重复性)

package my;
import java.util.Random;
public class HolleWorld
{

public static void main(String[] args)
{
	int[] result=new int[3];
	int count=0;
	Random rand=new Random();
	while(count<3)
	{
		int s=rand.nextInt(100);
		boolean exist=false;
		for(int i=0; i<count; i++)
		{
			if(result[i] == s)
			{
				exist = true;
				break;
			}
		}
		
		// 
		if(exist)
		{
			continue;
		}
		else
		{
			result[count] = s;
			count ++;
		}
	}
	
	
	for(int i=0; i<result.length; i++)
	{
		System.out.println("第" + (result[i] + 1) + "号获奖!");
	}


	}

}

猜你喜欢

转载自blog.csdn.net/weixin_43398418/article/details/87985345