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的 ...
随机推荐
- 2019牛客暑期多校第二场题解FH
F.Partition problem 传送门 题意:有2n个人,分两组,每组n个,要求sum(vij)最大值. 题解:n并不大我们可以枚举每个人是在1组还是2组爆搜. 代码: #include &l ...
- P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)
题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...
- struct结构体 重载运算符
struct node{ int x,y,z; }; bool operator<(node a,node b) { if(a.x!=b.x) return a.x<b.x; if(a.y ...
- C#与JavaScript中URL编码解码问题(转)
混乱的URI编码 JavaScript中编码有三种方法:escape.encodeURI.encodeURIComponent C#中编码主要方法:HttpUtility.UrlEncode.Serv ...
- play framework 相关
1.下载 官网下载解压,安装有jkd即可使用 2.helloworld $ activator new my-first-app play-java https://www.playframework ...
- Ansible配合Virtualenv安装配置
Ansible的两种安装模式(Centos7) 1.Yum包管理安装 #yum -y install ansible 2.Git源代码安装[推荐] git clone https://github.c ...
- javascript 内置对象和方法
一.自定义对象 方法1 /* 自定义对象 */ var sex= "gender" var person={"name": "tom", & ...
- PythonI/O进阶学习笔记_11.python的多进程
content: 1. 为什么要多进程编程?和多线程有什么区别? 2. python 多进程编程 3. 进程间通信 ======================================= ...
- Elasticsearch系列---结构化搜索
概要 结构化搜索针对日期.时间.数字等结构化数据的搜索,它们有自己的格式,我们可以对它们进行范围,比较大小等逻辑操作,这些逻辑操作得到的结果非黑即白,要么符合条件在结果集里,要么不符合条件在结果集之外 ...
- centOS7.1安装nginx与可能遇见的问题
一,安装nginx(系统:CentOS7.1) 1.Nginx下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz [root@linux src]# c ...