首页 > 其他 > 详细

1.14验证码 彩票

时间:2016-01-15 08:38:04      阅读:252      评论:0      收藏:0      [点我收藏+]
技术分享package lianxi;

import java.util.*;

public class lianxi114 {

    public static void main(String[] args) {
        // 验证码
        String str = "ab1c1defg2hijkl4mno6pq7r8st9u3vwsyz";
        System.out.print("请输入验证码:");
        for (int i = 0; i < 4; i++) {
            Random ran = new Random();
            int ran1 = ran.nextInt(str.length() - 1);
            System.out.print(str.substring(ran1, ran1 + 1));
        }
        System.out.println();
}
}
package lianxi;

import java.util.Random;
import java.util.Scanner;

public class caipiao {

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        System.out.println("请输入你需要机选的注数");
        int count = new Scanner(System.in).nextInt();
        for (int i = 1; i <= count; i++) {
            realize();
        }
    }

    public static void realize() {
        int red = 33;
        int blue = 16;
        int numLength = 7;
        int[] random = new int[numLength];
        outer: for (int i = 0; i < numLength - 1; i++) {
            int count = 0;
            int redNum = new Random().nextInt(red + 1);
            for (int j = 0; j < numLength - 1; j++) {
                if (redNum != random[j] && redNum != 0) {
                    count++;
                    if (count == numLength - 1) {
                        random[i] = redNum;
                        break;
                    } else {
                        continue;
                    }
                } else {
                    i--;
                    continue outer;
                }
            }
        }
        outer1: for (int i = numLength - 1; i < numLength; i++) {
            int blueNum = new Random().nextInt(blue + 1);
            for (int j = numLength - 1; j < numLength; j++) {
                if (blueNum != random[j]) {
                    random[i] = blueNum;
                    break;
                } else {
                    i--;
                    continue outer1;
                }
            }
        }
        for (int i = 0; i < numLength; i++) {
            if (i > 0 && i < numLength - 1) {
                if (i != numLength - 2) {
                    if (random[i] < 10) {
                        System.out.print("0" + random[i] + ",");
                    } else {
                        System.out.print(random[i] + ",");
                    }
                } else {
                    if (random[i] < 10) {
                        System.out.print("0" + random[i]);
                    } else {
                        System.out.print(random[i]);
                    }
                }
            } else {
                if (i != 0) {
                    if (random[i] < 10) {
                        System.out.println("蓝球:" + "0" + random[i]);
                    } else {
                        System.out.println("蓝球:" + random[i]);
                    }
                } else {
                    if (random[i] < 10) {
                        System.out.print("红球:" + "0" + random[i] + ",");
                    } else {
                        System.out.print("红球:" + random[i] + ",");
                    }
                }
            }
        }
    }

}

技术分享

1.14验证码 彩票

原文:http://www.cnblogs.com/zhanghaozhe8462/p/5132229.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!