java10幸运抽奖
public class jh_01_知识点回顾 {
public static void main(String[] args) {
int a = 10;
// 变量.标签.
// 重新给a赋值.
a = 20;
System.out.println(a);
// int r = 5;
//// 每个字母都要大写
// final double PI = 3.14;
// // area = ?
// // 不能分配最后的局部变量pi
//// The final local variable pi cannot be assigned.
//// It must be blank and not using a compound assignment
//// pi = 3.1415926;
// area = ?
}
}
import java.util.Random;
public class jh_02_生成随机数 {
public static void main(String[] args) {
// greater than or equal to 0.0 and less than 1.0.
// int random = (int) (Math.random()*10);
// System.out.println(random);
Random sc = new Random();
// Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive),
int a = sc.nextInt(3) + 1;
System.out.println(a);
}
}
public class jh_03_往容器里面增加一个元素 {
public static void main(String[] args) {
// // 能储存5个年龄容器
// int[] arr = new int[5];
// arr[0] = 17;
// arr[1] = 18;
// arr[2] = 19;
//
// for (int i = 0; i < arr.length; i++) {
// if (arr[i] == 0) {
// arr[i] = 0;
// }
//
// }
// 来个了嫩的16岁
// 找空位。
// for (int i = 0; i < arr.length; i++) {
// if(arr[i] == 0) {
// arr[i] = 23;
// break;
// }
//
// }
//
// for (int i = 0; i < arr.length; i++) {
// System.out.println(arr[i]);
// }
// 能存储5个姓名容器
// String [] arr = new String [5];
// arr[0] = "张三";
// arr[1] = "李四";
// arr[2] = "钻石王老五";
//
// for (int i = 0; i < arr.length; i++) {
// System.out.println(arr[i]);
// }
// // 找空位
// for (int i = 0; i < arr.length; i++) {
// if(arr[i] == null) {
// arr[i] = "赵六";
// break;
// }
// }
//
// for (int i = 0; i < arr.length; i++) {
// System.out.println(arr[i]);
// }
//
}
}
public class jh_04_删除容器里面的元素 {
public static void main(String[] args) {
// 能存储5个姓名容器
String [] arr = new String [7];
arr[0] = "张三";
arr[1] = "李四";
arr[2] = "王五";
arr[3] = "赵六";
arr[4] = "田七";
arr[5] = "王八";
arr[6] = "李九";
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
// 找到王五,不考虑不存在的情况。
int index = arr.length-1;
for (int i = 0; i < arr.length; i++) {
if("王五".equals(arr[i])) {
index = i ;
}
}
// 移动。从要删除元素的后一位,依次往前挪一位。
for(int i = index;i < arr.length - 1;i++ ) {
arr[i] = arr[i + 1];
}
// 挪完之后把最后多出来的置空。 --null
arr[arr.length-1]= null;
System.out.println("*************");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
import java.util.Scanner;
public class jh_05_阶段1_练习_实现菜单的输出显示 {
/*
* 需求说明
* 输出菜单
* 选择菜单编号, 输出菜单信息
* 如果编号选择错误, 输出“您的输入有误!”
* 1: 罗列信息, ---输出语句
* 2: 输入选择, ---键盘录入
* 3: 根据选择做等值判断 --- 选择结构switch
*/
public static void main(String[] args) {
// 创建键盘录入对象
Scanner sc = new Scanner(System.in);
// 1: 罗列信息, ---输出语句
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("*******************************");
// 2: 输入选择, ---键盘录入
System.out.print("请选择菜单:");
int nome = sc.nextInt();
// 3: 根据选择做等值判断 --- 选择结构switch
switch (nome) {
case 1:
System.out.println("奖客富翁系统 > 注册");
break;
case 2:
System.out.println("奖客富翁系统 > 登录");
break;
case 3:
System.out.println("奖客富翁系统 > 抽奖");
break;
default:
System.out.println("您的输入有误!");
break;
}
}
}
import java.util.Scanner;
public class jh_06_阶段2_练习_实现循环执行功能 {
public static void main(String[] args) {
// 创建键盘录入对象
Scanner sc = new Scanner(System.in);
String answer = null;
do {
// 1: 罗列信息, ---输出语句
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("*******************************");
// 2: 输入选择, ---键盘录入
System.out.print("请选择菜单:");
int nome = sc.nextInt();
// 3: 根据选择做等值判断 --- 选择结构switch
switch (nome) {
case 1:
System.out.println("奖客富翁系统 > 注册");
break;
case 2:
System.out.println("奖客富翁系统 > 登录");
break;
case 3:
System.out.println("奖客富翁系统 > 抽奖");
break;
default:
System.out.println("您的输入有误!");
break;
}
System.out.println("继续吗? y/n");
answer = sc.next();
System.out.println();
} while ("y".equals(answer));
System.out.println("系统退出,谢谢使用. ");
}
}
import java.util.Random;
import java.util.Scanner; public class jh_07_阶段3_练习_实现注册 {
public static void main(String[] args) {
// 创建键盘录入对象
Scanner sc = new Scanner(System.in);
String answer = null;
do {
// 1: 罗列信息, ---输出语句
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("*******************************");
// 2: 输入选择, ---键盘录入
System.out.print("请选择菜单:");
int nome = sc.nextInt();
// 3: 根据选择做等值判断 --- 选择结构switch
switch (nome) {
case 1:
System.out.println("奖客富翁系统 > 注册");
// 阶段2,实现注册
System.out.println("请输入个人信息");
System.out.println("用户名: ");
String userName = sc.next();
System.out.println("密码: ");
String passWrod = sc.next();
// 随机生成卡号:
Random r = new Random();
int cardNum = r.nextInt(9000) + 1000;
System.out.println();
System.out.println("注册成功:请记好您的会员卡号:");
System.out.println("用户名\t密码\t卡号");
System.out.println(userName + "\t" + passWrod + "\t" + cardNum);
break;
case 2:
System.out.println("奖客富翁系统 > 登录");
break;
case 3:
System.out.println("奖客富翁系统 > 抽奖");
break;
default:
System.out.println("您的输入有误!");
break;
}
System.out.println("继续吗? y/n");
answer = sc.next();
System.out.println();
} while ("y".equals(answer));
System.out.println("系统退出,谢谢使用. "); } }
import java.util.Random;
import java.util.Scanner; public class jh_08_阶段4_练习_实现登录功能 {
/*
* 需求说明
* 输入注册时的用户名和密码,
* 登录成功,提示欢迎信息
* 如果用户名和密码输入错误,
* 提示用户继续输入,最多有3次输入机会
*/
public static void main(String[] args) {
// 创建键盘录入对象
Scanner sc = new Scanner(System.in);
String answer = null;
String passWrod = null;
String userName = null;
do {
// 1: 罗列信息, ---输出语句
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("*******************************");
// 2: 输入选择, ---键盘录入
System.out.print("请选择菜单:");
int nome = sc.nextInt();
// 3: 根据选择做等值判断 --- 选择结构switch
switch (nome) {
case 1:
System.out.println("奖客富翁系统 > 注册");
// 阶段2,实现注册
System.out.println("请输入个人信息");
System.out.println("用户名: ");
userName = sc.next();
System.out.println("密码: ");
passWrod = sc.next();
// 随机生成卡号:
Random r = new Random();
int cardNum = r.nextInt(9000) + 1000;
System.out.println();
System.out.println("注册成功:请记好您的会员卡号:");
System.out.println("用户名\t密码\t卡号");
System.out.println(userName + "\t" + passWrod + "\t" + cardNum);
break;
case 2:
System.out.println("奖客富翁系统 > 登录");
for (int i = 1; i <= 3; i++) {
System.out.println("请输入用户名:");
String userN = sc.next();
System.out.println("请输入密码:");
String passW = sc.next();
// 跟注册时候的内容做判断比较。
boolean result = userN.equals(userName) && passW.equals(passWrod);
if (result) {
System.out.println("欢迎您," + userN);
break;// 对就退出循环。
} else {
// 输错,提示还有几次机会。
System.out.println("输入有误,您还有" + (3 - i) + "次机会。");
}
}
break;
case 3:
System.out.println("奖客富翁系统 > 抽奖");
break;
default:
System.out.println("您的输入有误!");
break;
}
System.out.println("继续吗? y/n");
answer = sc.next();
System.out.println();
} while ("y".equals(answer));
System.out.println("系统退出,谢谢使用. "); } }
import java.util.Random;
import java.util.Scanner; public class jh_09_阶段5_练习_实现幸运抽奖 {
/*
* 需求说明
* 登录成功后,用户选择幸运抽奖菜单,进入幸运抽奖功能
* 输入会员卡号,系统生成5个4位随机数作为幸运数字
* 如果会员卡号是其中之一,
* 则成为本日幸运会员;否则不是幸运会员
*/
public static void main(String[] args) {
// 创建键盘录入对象。
Scanner sc = new Scanner(System.in);
String answer = null;
String passWrod = null;
String userName = null;
// 创建随机数对象。
Random r = new Random();
do {
// 1: 罗列信息,---输出语句
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1:注册");
System.out.println("\t2:登录");
System.out.println("\t3:抽奖");
System.out.println("**************************"); // 2:输入选择,--- 键盘录入。
System.out.println("请选择菜单:");
int choose = sc.nextInt(); // 3:根据选择做等值判断 ---- 选择结构switch
switch (choose) {
case 1:
System.out.println("奖客富翁系统 > 注册");
// 阶段2,实现注册
System.out.println("请输入个人信息:");
System.out.println("用户名:");
userName = sc.next();
System.out.println("密码:");
passWrod = sc.next();
// 随机生成卡号: int cardNum = r.nextInt(9000) + 1000;
System.out.println();
System.out.println("注册成功:请记好您的会员卡号:");
System.out.println("用户名\t密码\t卡号");
System.out.println(userName + "\t" + passWrod + "\t" + cardNum);
break;
case 2:
System.out.println("奖客富翁系统 > 登录");
for (int i = 1; i <= 3; i++) {
System.out.println("请输入用户名:");
String userN = sc.next();
System.out.println("请输入密码:");
String passW = sc.next();
// 跟注册时候的内容做判断比较。
boolean result = userN.equals(userName) && passW.equals(passWrod);
if (result) {
System.out.println("欢迎您," + userN);
break;// 对就退出循环。
} else {
// 输错,提示还有几次机会。
System.out.println("输入有误,您还有" + (3 - i) + "次机会。");
}
}
break;
case 3:
System.out.println("奖客富翁系统 > 抽奖");
System.out.println("请输入您的卡号:");
int cardN = sc.nextInt();
// 生成五个幸运卡号,存储在容器里面
int[] luckyNum = new int[5];
for (int i = 0; i < luckyNum.length; i++) {
luckyNum[i] = r.nextInt(9000) + 1000;
}
/*
* 输出本日的幸运卡号:
*/
System.out.print("本日的幸运数字:");
for (int i : luckyNum) {
System.out.print(i + " ");
}
System.out.println();
// 判断容器里的幸运数是否有您的卡号。
boolean flag = false;
for (int i = 0; i < luckyNum.length; i++) {
if (luckyNum[i] == cardN) {
flag = true;
break;
}
}
if (flag) {
System.out.println("恭喜恭喜小姐姐,你中奖了。");
} else {
System.out.println("抱歉,你不是本日的幸运会员");
}
break;
default:
System.out.println("您的输入有误!");
break;
}
// 询问是否继续y/n?
System.out.println("继续吗?y/n");
answer = sc.next();
System.out.println();
} while ("y".equals(answer)); System.out.println("系统退出,谢谢使用。");
} }
import java.util.Random;
public class test {
public static void main(String[] args) {
// 1 -- 3;
// 4位数 1000---9999
/*
* 1----9999
* 1000----9999
* 1 --- 8999
* 1000 --- 9999
*/
// int random =
// (int) (Math.random()*8999 + 1000);
// System.out.println(random);
Random r = new Random();
int cardNum = r.nextInt(9000) + 1000;
System.out.println(cardNum);
}
}
java10幸运抽奖的更多相关文章
- JS实现幸运抽奖页面
JS实现简单的幸运抽奖页面 效果图: 图片素材 : 代码如下,复制即可使用: <!DOCTYPE html> <html> <head lang="en&quo ...
- java小项目之:抽奖系统!java初学者必备(内附源码)
[Java]Java摇奖源码,Java抽奖源码,Java随机抽奖源码 任务描述 本次任务要求为某商场开发一套幸运抽奖系统,客户必须首先注册成为该商场会员,会员登录成功后,就可以参加抽奖活动了.注册 用 ...
- java小项目——抽奖系统
来了来了!这不又到考试周了吗!愁人,又得复习,复习,复习!这段时间每天都在复习线代和高数!(说是复习,说实话其实是在预习,啊哈哈哈哈哈),得有一段时间都没有学到新的知识了,代码感觉都生疏了,惆怅.博客 ...
- JAVA理解逻辑程序的书上全部重要的习题
今天随便翻翻看以前学过JAVA理解逻辑程序的书上全部练习,为了一些刚学的学弟学妹,所以呢就把这些作为共享了. 希望对初学的学弟学妹有所帮助! 例子:升级“我行我素购物管理系统”,实现购物结算功能 代码 ...
- html5高级
Html5高级 项目回顾 Day 01 第三阶段知识体系: (1)AJAX异步请求 数据库.PHP.HTTP.原生AJAX.jQuery中的AJAX (2)HTML5高级特性 九大新特性 (3)Boo ...
- Java 零基础之作业小练习
[练习1] 需求:输入学员的名称及总科目数并显示每项科目成绩的分数,算出总成绩. package demo2; import java.util.Scanner; //先import Scanner语 ...
- 选择流程—— switch if else结构
一.switch switch(表达式){ case 常量1: 语句; break; case 常量2: 语句; break; … default; 语句; } 例题:运用switch结构实现购物管理 ...
- switch处理多分支结构
import java.util.Scanner; /** * Created by liwenj on 2017/7/17. */ public class test9 { public stati ...
- WAF开放规则定义权:专家策略+用户自定义策略=Web安全
在第一期“漫说安全”栏目中,我们用四格漫画的形式介绍了基于深度学习的阿里云WAF到底智能在哪里,能帮客户解决什么问题. 在今天的这期栏目里,我们依然通过漫画这种通俗易懂的方式,与大家分享阿里云WAF的 ...
随机推荐
- Spring Security 实战干货: 简单的认识 OAuth2.0 协议
1.前言 欢迎阅读 Spring Security 实战干货 系列文章 .OAuth2.0 是近几年比较流行的授权机制,对于普通用户来说可能每天你都在用它,我们经常使用的第三方登录大都基于 OAuth ...
- PHP的一些安全设置
小伙伴们新年好啊,又有半个月没有更新博客了.更新也比较随性,想起什么就写点什么,方便和大家工作同学习总结. 最近和同事说起了PHP安全相关的问题,记录下一些心得体会. 由于脚本语言和早期版本设计的诸多 ...
- pqsql 防注入
在数据库查询时经常会遇到根据传入的参数查询内容的情况,传入的参数有可能会带有恶意代码,比如or 1=1,这样where判断为true,就会返还所有的记录.为了解决这个问题,可以在参数外面包一层单引号, ...
- Mysql中使用mysqldump进行导入导出sql文件
纪念工作中的第一次删库跑路的经历 今天接到一个任务,是将一个测试库数据导到另一个测试库,然而我们公司的数据库是不让直连的,所以只能通过远程连接进行导库操作. 老大布置任务的时候让用dump命令进行操作 ...
- STM32动态内存分配需要注意的地方
STM32进行动态内存分配是需要注意动态内存分配大小不要超过.S文件中设置Heap Size大小 如图所示: 0x4000 :可以分配得最大字节是16384bytes 这个地方malloc的大小超过了 ...
- 读取配置文件,appsettings.json和注入ICO
https://www.cnblogs.com/knowledgesea/p/7079880.html 引入Nuget的两个类库 Microsoft.Extensions.Configuration ...
- dp——洛谷 P1541 乌龟棋 —— by hyl天梦
题目:(转自 https://www.luogu.com.cn/problem/P1541) 题目描述 乌龟棋的棋盘是一行NN个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第NN格是 ...
- pyton 封装
定义:在类中将方法和属性隐藏起来 一.私有化 1.格式 __名字,在名字前加双下划线 2.私有化对象 对象属性 静态属性 普通方法 3.作用 1)在类的外面不能直接调用类的方法和属性 2)类的属性值不 ...
- 【强化学习RL】model-free的prediction和control —— MC,TD(λ),SARSA,Q-learning等
本系列强化学习内容来源自对David Silver课程的学习 课程链接http://www0.cs.ucl.ac.uk/staff/D.Silver/web/Teaching.html 本文介绍了在m ...
- .net core webapi搭建(1)
创建一个webapi项目 修改launchSettings.json 将launchSettings.json中的IIS启动删掉.别问我为啥 原因就是IISEXPRESS有时候需要我手动重启.我嫌麻 ...