java 小项目 双色球选号

 还是用汉语补充一下吧,

主要分为:(如测试中注释所写)

一,随机生成红球and 蓝球

二,进行排序

三,红球可能出现重复, 去重

四,测试



package DoubleBall;
//*function :the double chromosphere generation system.
	/*
	 * 1 creatRedball
	 * 2 creatBlueBall
	 * 3 sortOfBall
	 * 4 RemoveRedo
	 * 5 Test and print
	 */
public class TestOfDoubleBall {
	public static void main(String[] args) {
		// creatRedball
		CreatRedBall creatRedBall = new CreatRedBall();
		int[]  arr1 = creatRedBall.creatRedBall();
		// creatBlueBall.
		CreatBlueBall creatBlueBall = new CreatBlueBall();
		int arrblue =  creatBlueBall.creatBlueBall();
		
		//sort and remove the redo red ball.
		RemoveRedo removeRedo = new RemoveRedo();
		int[] arr2 = removeRedo.removeRedo(arr1);
		// The last print the result.
		System.out.println("*********First prize the double chromosphere number is:********");
		 for(int i = 0;i<arr2.length;i++) {
			 System.out.print(" "+arr2[i]);
		 }
		 System.out.println("+ "+arrblue );
	}
 
	
}
 
package DoubleBall;
/*
 * function :creatBlueball;
 *five random numbers from 1-32;
 */
import java.util.Random;

public class CreatRedBall {
      public static int [] creatRedBall() {
    	  int [] arr = new int [6];
    	  for(int i = 0;i<arr.length;i++) {
    		arr [i] = (int) (Math.random()*32+1);   
    	  }
		return arr;
      }
}
package DoubleBall;
/*function :creatBlueball;
 * Random generation number between 1-16;
 */
public class CreatBlueBall {
	public static int creatBlueBall() {
		int blue = (int)Math.random()*16+1;
		return blue; 
	}

	public CreatBlueBall() {
		super();
		// TODO Auto-generated constructor stub
	} 
}

package DoubleBall;
/*function:sort of the array; 
 */
public class SortOfBall {
           public static int[] sortOfBall(int[] arr) {
        	   for(int i = 0;i<arr.length-1;i++) {
        		   for(int j = 0;j<arr.length-1-i;j++) {
        			   if(arr[j]>arr[j+1]) {
        				   arr[j]= arr[j]^arr[j+1];
        				   arr[j+1]= arr[j]^arr[j+1];
        				   arr[j]= arr[j]^arr[j+1];
        			   }
        		   }
        	   }
			return arr; 
           }
}

package DoubleBall;
/*function :remove redo number from the 
 * five random numbers  and sort of it ; 
 */
public class RemoveRedo {
 public static int[] removeRedo(int[] arr) {
	 while(true) 
	 {
	   SortOfBall sortOfBall = new SortOfBall();
	   int[] arr1 = sortOfBall.sortOfBall(arr);
	   int i= 0;
	    for(  i = 0;i<arr1.length-1;i++) 
	    {
		 if(arr[i]==arr[i+1]) 
		    {
			 arr[i] = (int)Math.random()*32+1;
		     }
		  
	     }
	    if(i==5) 
		    {
			 break;
		    }
    }
	 return arr;
  }
}

撸码不易,给个赞就成。转载请标明出处




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值