import java.util.Scanner;

class SsqGame {
public static void main(String[] args) {
int total = 0;//买了几注
int[] num = new int[7];
boolean flag = false;
do{
System.out.println("*****欢迎进入双色球彩票系统*****");
System.out.println(" 1.购买彩票 ");
System.out.println(" 2.查看开奖 ");
System.out.println(" 3.退出 ");
System.out.println("********************************");
Scanner sc = new Scanner(System.in);
System.out.println("请选择菜单:");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("请选择您要购买几注彩票:");
int record = sc.nextInt();
total = record * 2;
for (int i = 0;i < 7 ;i++ ) {
if (i < 6) {
System.out.println("购买红色球,请选择一个1-33之间的号码:");
int red = sc.nextInt();
num[i] = red;
}else{
System.out.println("购买蓝色球,请选择一个1-16之间的号码:");
int blue = sc.nextInt();
num[i] = blue;
}
}
System.out.print("您一共购买了" + record + "注,共需支付" + total + "元,您所选号码为:");
print(num);
System.out.println(); break;
case 2:
//随机生成开奖号码
int luckNum[] = getLuckNum();
System.out.print("本次中奖号码为:");
print(luckNum);
System.out.print("已买的彩票号:");
print(num);
//比较中奖号码和已买号码
int result = resultComparation(num,luckNum);
System.out.println("中奖信息:");
if (result == 1) {
System.out.println("恭喜您中了一等奖!");
}else if (result == 2) {
System.out.println("恭喜您中了二等奖!");
}else if (result == 3) {
System.out.println("恭喜您中了三等奖!");
}else if (result == 4) {
System.out.println("恭喜您中了四等奖!");
}else if (result == 5) {
System.out.println("恭喜您中了五等奖!");
}else if (result == 6) {
System.out.println("恭喜您中了六等奖!");
}else{
System.out.println("很遗憾没有中奖");
}
System.out.println(); break;
case 3:
flag = true;
break;
default:
System.out.println("请输入正确的选项");
break; }
}while(true);
} public static void print(int[] arr){
for (int i = 0;i < arr.length ;i++ ) {
System.out.print(arr[i] + " ");
}
} public static int[] getLuckNum(){
int luckNum[] = new int[7];
for (int i = 0;i < luckNum.length ;i++ ) {
if (i < luckNum.length - 1) {
a:for (int j = 0;j < luckNum.length-i ;j++ ) {
int m = (int)(Math.random()*33 + 1);
if (m != luckNum[j]) {
luckNum[j] = m;
}
else{
break a;
}
}
}else{
luckNum[i] = (int)(Math.random()*16 + 1);
}
}
return luckNum;
} public static int resultComparation(int[] num,int[] luckNum){
int redcount = 0;//红球相同个数
int bluecount = 0;//蓝球相同个数
int result = 0;//中奖等级
//将所买号码中每个数字与中奖号码进行比较,计算红球和蓝球各自相同的个数
for (int i = 0;i < num.length ;i++ ) {
if (i < num.length - 1) {
int m = num[i];
for (int j = 0;j < luckNum.length - 1 ;j++ ) {
if (m == luckNum[j]) {
redcount++;
}
}
}else{
if (num[num.length-1] == luckNum[luckNum.length-1]) {
bluecount++;
}
}
}
//确定中奖等级
if (redcount == 6 && bluecount == 1) {
result = 1;
}else if (redcount == 6 && bluecount == 0) {
result = 2;
}else if (redcount == 5 && bluecount == 1) {
result = 3;
}else if ((redcount == 5 && bluecount == 0) ||(redcount == 4 && bluecount == 1)) {
result = 4;
}else if ((redcount == 4 && bluecount == 0) ||(redcount == 3 && bluecount == 1)) {
result = 5;
}else if (redcount == 0 && bluecount == 1) {
result = 6;
}else{
result = 0;
}
return result;
}
}

day07作业的更多相关文章

  1. day07 作业

    作业(必做题):#1. 使用while循环输出1 2 3 4 5 6 8 9 10count=0while count<11: if count==7: count+=1 continue pr ...

  2. Python:Day07 作业

    三级菜单: 自己做的代码: china = { '江苏':{ '南京':{ '江宁':{}, '白下':{}, '栖霞':{}, '江淮':{}, '浦口':{} }, '宿迁':{ '宿城区':{} ...

  3. python day07作业答案

    1. sum=0 a=input() for i in a: sum=sum+int(i)**3 if sum==int(a): print('水仙数') 2. lst=[100,2,6,9,1,10 ...

  4. python day07作业

  5. day07作业猜年龄游戏

    # 给定年龄,用户可以猜三次年龄 # # 年龄猜对,让用户选择两次奖励 # # 用户选择两次奖励后退出 get_prize_dict = {} # 获取的奖品信息 age = 18 inp_count ...

  6. python 作业

    Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...

  7. DSB

    Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...

  8. 08_Java基础语法_第8天(Eclipse)_讲义

    今日内容介绍 1.Eclipse开发工具 2.超市库存管理系统 01Eclipse的下载安装 * A: Eclipse的下载安装  * a: 下载 * http://www.eclipse.org ...

  9. Day07 jdk5.0新特性&Junit&反射

    day07总结 今日内容 MyEclipse安装与使用 JUnit使用 泛型 1.5新特性 自动装箱拆箱 增强for 静态导入 可变参数方法 枚举 反射 MyEclipse安装与使用(yes) 安装M ...

随机推荐

  1. MyBatis.4关联

    关联.多对一关联查询 package org.mybatis.example.dao; import java.util.Date; //雇员类 public class Emp { private ...

  2. apache.commons.io.FileUtils的常用操作

    至于相关jar包可以到官网获取 http://commons.apache.org/downloads/index.html package com.wz.apache.fileUtils; impo ...

  3. C++:(拷贝,继承,智能指针)练习

    #include <iostream> #include <string> #include <memory> #include <functional> ...

  4. 【Asp.net入门02】搭建Asp.net开发环境

    本节主要讲解: 什么是asp.net asp.net开发和运行环境介绍 1.什么是ASP.NET Asp.net不是一种编程语言,而是一种开发技术.我们可以利用这种技术所提供的类库,使用C#或者VB编 ...

  5. Java入门:Java中获取键盘输入值的三种方法

    Java程序开发过程中,需要从键盘获取输入值是常有的事,但Java它偏偏就没有像c语言给我们提供的scanf(),C++给我们提供的cin()获取键盘输入值的现成函数!Java没有提供这样的函数也不代 ...

  6. python 中的multiprocessing 模块

    multiprocessing.Pipe([duplex]) 返回2个连接对象(conn1, conn2),代表管道的两端,默认是双向通信.如果duplex=False,conn1只能用来接收消息,c ...

  7. svn 节点处冲突 解决

    问题描述: [root@localhost ] $ svn up 正在升级 ‘.’: 已跳过 ‘bg0605’ – 节点处于冲突状态 版本 175. 冲突概要: 跳过的路径:1 解决方法: 当前目录下 ...

  8. 编译的java工程压缩上传到linux服务器上后,中文的类名显示乱码

    首先声明,类名是用中文命名的,这个别人写的,不允许修改. 本地用7zip软件压缩成zip包,传到服务器解压,发现中文的class文件名称是乱码. 解决办法: 方法一:使用jar命令打成jar包,传到服 ...

  9. NGINX配置详解及应用

    目录 NGINX    1 1.1    目录结构    1 1.2    基础配置    1 1.3    location    5 1.4    虚拟主机    5 1.5    状态模块    ...

  10. 05.UIDynamic

    CHENYILONG Blog 05.UIDynamic Fullscreen © chenyilong. Powered by Postach.io Blog