day07作业
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作业的更多相关文章
- day07 作业
作业(必做题):#1. 使用while循环输出1 2 3 4 5 6 8 9 10count=0while count<11: if count==7: count+=1 continue pr ...
- Python:Day07 作业
三级菜单: 自己做的代码: china = { '江苏':{ '南京':{ '江宁':{}, '白下':{}, '栖霞':{}, '江淮':{}, '浦口':{} }, '宿迁':{ '宿城区':{} ...
- 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 ...
- python day07作业
- day07作业猜年龄游戏
# 给定年龄,用户可以猜三次年龄 # # 年龄猜对,让用户选择两次奖励 # # 用户选择两次奖励后退出 get_prize_dict = {} # 获取的奖品信息 age = 18 inp_count ...
- python 作业
Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...
- DSB
Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...
- 08_Java基础语法_第8天(Eclipse)_讲义
今日内容介绍 1.Eclipse开发工具 2.超市库存管理系统 01Eclipse的下载安装 * A: Eclipse的下载安装 * a: 下载 * http://www.eclipse.org ...
- Day07 jdk5.0新特性&Junit&反射
day07总结 今日内容 MyEclipse安装与使用 JUnit使用 泛型 1.5新特性 自动装箱拆箱 增强for 静态导入 可变参数方法 枚举 反射 MyEclipse安装与使用(yes) 安装M ...
随机推荐
- npm publish gives “unscoped packages cannot be private”
解决方法: npm publish --access public 详细参考此处
- [CQOI2016] 手机号码 (数位dp)
link $solution:$ $10^{10} \leq L \leq R < 10^{11}$这个数据范围很容易想到数位$dp$. 依照题意模拟即可. #include<iostre ...
- MVC 中@Html.DropDownListFor() 设置选中项 这么不好使 ? [问题点数:40分,结帖人lkf181]
http://bbs.csdn.net/topics/390867060 由于不知道错误原因在哪 我尽量把代码都贴出来吧:重点是:在 Controller 类里 我给 SelectListItem集合 ...
- 统计学习方法:CART算法
作者:桂. 时间:2017-05-13 14:19:14 链接:http://www.cnblogs.com/xingshansi/p/6847334.html . 前言 内容主要是CART算法的学 ...
- FPGA/SOPC学习转载
转自小時不識月http://www.cnblogs.com/yuphone/archive/2010/08/27/docs_plan.html 新网址为:http://andrewz.cn [连载计划 ...
- mysql 优化总结
1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. (laravel 可以使用 debugbar 包,可以及时发现低效 sql 语句,不使用索 ...
- sql 事务的四种隔离级别
在 SQL 标准中定义了四种隔离级别,每一种级别都规定了一个事务中所做的修改,哪些在事务内和事务间是可见的,哪些是不可见的.较低级别的隔离通常可以执行更高的并发,系统的开销也更低. read unco ...
- python eval 用法
eval 功能:将字符串str当成有效的表达式来求值并返回计算结果. 语法: eval(source[, globals[, locals]]) -> value 参数: source:一个Py ...
- Mongo副本集搭建
解压mongodb-linux-x86_64-rhel70-3.2.0.tgz 将解压后的bin路径添加到系统环境变量,保证mongo.mongod等命令可用 创建副本集目录mongo/27017.2 ...
- Showbo.js弹窗实现(jquery)
一.搭建环境 下载showBo.js和showBo.css 下载链接:https://pan.baidu.com/s/1iUUlKXFNXCBEvBnds4ECIA 密码:its4 显示效果图: 二 ...