彩票系统 35选7
2015-09-13 12:11
127 查看
代码如下:
public class Main { public static void main(String[] args) { // write your code here Main main = new Main(); int[] yStr = new int[7]; String regexID = "\\d{15}(\\d\\d[0-9xX])?"; Scanner scanner = new Scanner(System.in); System.out.println("1、彩票系统35选7"); System.out.println("———————————— 购买彩票 ————————————"); System.out.println("身份证号:"); String iD = scanner.next(); if (!iD.matches(regexID)) { System.out.println("请正确输入身份证号码"); main(args); } System.out.println("购买号码:(输入(1-35)的7个数字,以逗号间隔)"); for (int i = 0; i < 7; i++) { yStr[i] = scanner.nextInt(); } main.isEquals(yStr); } /** * 比较彩票 * * @param yStr */ private void isEquals(int[] yStr) { int[] sStr = new int[7]; int count = 0; StringBuffer stringBuffer = new StringBuffer(); for (int s = 0; s < 7; s++) { sStr[s] = (int) (Math.random() * 35 + 1); stringBuffer.append(sStr[s] + "-"); } for (int i = 0; i < 7; i++) for (int j = 0; j < 7; j++) { if (sStr[i] == yStr[j]) { count++; } } System.out.println("———————————— 彩票开奖 ————————————"); System.out.println("[" + stringBuffer.substring(0, stringBuffer.length() - 1).toString() + "]"); switch (count) { case 1: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:5元"); break; case 2: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:10元"); break; case 3: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:20元"); break; case 4: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:50元"); break; case 5: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:100元"); break; case 6: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:200元"); break; case 7: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:" + count); System.out.println("中奖金额:500万元"); break; case 0: System.out.println("———————————— 兑奖信息 ————————————"); System.out.println("中奖个数:0"); System.out.println("中奖金额:谢谢您捐赠的2元钱!"); break; } } }
相关文章推荐
- 基本类型和引用类的区别
- 操作系统内核Hack:(一)实验环境搭建
- 【面试题】面试题集四
- Hadoop权威指南第4版第7章Anatomy of a MapReduce Job Run
- 扩展系统功能——装饰模式(四):透明与半透明装饰模式,装饰模式注意事项,装饰模式总结
- 2015.9.13
- 给我半个小时记录一下最近
- 解决Eclipse导入Android工程出错
- LeetCode_pascals-triangle
- 使用apktool + idea 调试smali
- kick start 无人值守安装Linux
- maven 使用
- 网络连接之——HttpClient(doGet和doPost)
- 年总结(三):风雨征程一年机房路
- poj 3252 Round Numbers
- mysql中join的四种连接
- 斯坦福Developing iOS 8 Apps学习笔记(五)
- Matlab实时监控股票交易数据之Timer函数应用实例
- 【软考视频基础知识】——数据结构
- 在BootStrap的modal中使用Select2