java数组实现买彩票(平移覆盖思想)

 1 package com.wh.shuzu;
 2 /**
 3  * 买彩票
 4  * @author 贾相如同学
 5  * 平移覆盖思想
 6  */
 7 public class Lotery3 {
 8 
 9     public static void main(String[] args) {
10         int a[] = {1,2,3,4,5,6,7,8,9,10,11};
11         for(int i =0;i<5;i++){
12             //每覆盖一次,随机数的范围就少一个
13             int temp = (int)(Math.random()*(11-i));
14             //打印输出随机数的数组值
15             System.out.println(a[temp]);
16             //从第temp个数开始平移
17             for(int j = temp;j<a.length-1;j++) 
18                 a[j] = a[j+1];
19         }
20     }
21 }

 

posted @ 2016-09-13 17:56  奋斗的少年WH  阅读(233)  评论(0编辑  收藏  举报