zoukankan      html  css  js  c++  java
  • 作业 书上的题看不懂2

    //摇奖程序
            
            //偷懒不排大小
                    Set <Integer> a=new HashSet<Integer>();
                    
                    Random b=new Random();
                    
                    for(int i=0;;i++){
                        a.add(b.nextInt(31)+1);
                        if(a.size()==7){
                        break;
                        }
                    }
    
                  System.out.println("中奖的号码是");
                    for(int i:a){System.out.print(i+"  ");}
                    System.out.println();
                    
                    //排序
                    int[] c=new int[7];
        int x=0;
            for(int i=0;x<7;i++){
         int d;
         int z=1;
         d=b.nextInt(31)+1;
         
         for(int j=0;j<x;j++){
          if(c[j]==d){
           z+=2;
          }
         }
         if(z==1){c[x]=d;x++;}
         
            }//冒泡排序 int f=0; for(int i=0;i<7;i++){ for(int j=i;j<6;j++){ if(c[i]>c[j+1]){ f=c[i]; c[i]=c[j+1]; c[j+1]=f; } } } for(int i:c){ System.out.print(i+" "); } System.out.println(); //产生验证码 String g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789"; String []h=new String[4]; for(int i=0;i<=3;i++){ int d=b.nextInt(g.length()); h[i]=g.substring(d, d+1); } for(String x:h){ System.out.print(x); } System.out.println();
  • 相关阅读:
    2019.5.28
    蓝桥杯2017Java B组---分巧克力and承压计算
    看似忙碌的背后我都干了点什么
    3.9个人总结
    3.2个人总结
    2.23个人总结
    2.16个人总结
    2019.01.27个人总结
    1.19个人总结
    12.22个人总结
  • 原文地址:https://www.cnblogs.com/storm47/p/5267855.html
Copyright © 2011-2022 走看看