不用Random函数实现java双色球

   public class Ssq {
    	public static void main(String[] args) {
    		Scanner sc=new Scanner(System.in);
    		int h[]=new int[7];
    		boolean b=true;
    		for(int i=0;i<6; ) {
    			System.out.println("请输入第"+(i+1)+"个1-32号的不重复红球");
    			int k=sc.nextInt();
    			if(k>=1 && k<=32) {//判断红球号码大小
    				for(int j=0;j<=i;j++) {//判断红球号码是否重复
    					if(k==h[j]) {//如果重复b变成false
    						b=false;
    					}
    				}
    				if(b==true) {//如果b一直是true则没有重复
    					h[i]=k;
    					i++;
    				}else {//上一步输入了重复的数字,需要重新输入
    					System.out.println("请重新输入有效值");
    					b=true;//将b重置为true重新循环
    				}
    				
    			}else {
    				System.out.println("请重新输入有效值");
    			}
    		}
    		System.out.println("请输入一个蓝色球号码在1-15");
    		boolean c=true;
    		while(c) {
    			int x=sc.nextInt();
    			if(x>=1 && x<=15) {
    				h[6]=x;
    				c=false;//如果满足条件设置成false结束循环
    			}else {
    				System.out.println("请重新输入篮球号码");
    			}
    		}
    		
    		System.out.print("选出的双色球号码是:");
    		for(int z:h) {
    			System.out.print("["+z+"]");
    		}
    		System.out.println();
    		System.out.println("其中蓝色球是:"+h[6]);
    	}
    }

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值