「java抽奖活动需求」Java抽奖
今天给各位分享java抽奖活动需求的知识,其中也会对Java抽奖进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、一道Java题目:一项抽奖活动要求你从整数1-49之间选择6个不同的数字,编写一个程序来完成这项工作,并生成5组
- 2、如何用java技术实现幸运抽奖活动系统
- 3、商场推出幸运抽奖活动的java初级代码编写
- 4、java抽奖程序
一道Java题目:一项抽奖活动要求你从整数1-49之间选择6个不同的数字,编写一个程序来完成这项工作,并生成5组
class TakeOutAward {
TakeOutAward() {
numbers = new int[6];
}
void takeOut() {
int count = 6;
while(count 0) {
int rand = (int)(Math.random() * 48 + 1);
switch(count) {
case 6:
numbers[0] = rand;
count--;
break;
case 5:
if(numbers[0] == rand) {
continue;
}
numbers[1] = rand;
count--;
break;
case 4:
if(numbers[0] == rand || numbers[1] == rand) {
continue;
}
numbers[2] = rand;
count--;
break;
case 3:
if(numbers[0] == rand || numbers[1] == rand || numbers[2] == rand) {
continue;
}
numbers[3] = rand;
count--;
break;
case 2:
if(numbers[0] == rand || numbers[1] == rand || numbers[2] == rand || numbers[3] == rand) {
continue;
}
numbers[4] = rand;
count--;
break;
case 1:
if(numbers[0] == rand || numbers[1] == rand || numbers[2] == rand
|| numbers[3] == rand || numbers[4] == rand) {
continue;
}
numbers[5] = rand;
count--;
break;
}
}
}
void display() {
for(int i = 0; i numbers.length;i++) {
System.out.print (numbers[i] + " ");
}
}
int[] numbers;
}
public class TakeOutAwardTest {
public static void main(String[] args) {
TakeOutAward wusheng = new TakeOutAward();
for(int i = 0; i 5; i++) {
System.out.print("第" + (i + 1) + "次抽奖结果为:");
wusheng.takeOut();
wusheng.display();
System.out.println ();
}
}
}
如何用java技术实现幸运抽奖活动系统
import java.util.Scanner;
public class LuckyNumber {
/**
* 幸运抽奖
*/
public static
void main(String[] args) {
String answer
= "y"; // 标识是否继续
String
userName = ""; // 用户名
String
password = ""; // 密码
int cardNumber
= 0; // 卡号
boolean
isRegister = false; // 标识是否注册
boolean
isLogin = false; // 标识是否登录
int max =
9999;
int min =
1000;
Scanner input
= new Scanner(System.in);
do {
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.抽奖");
System.out.println("***************************");
System.out.print("请选择菜单:");
int choice =
input.nextInt();
switch
(choice) {
case 1:
System.out.println("[奖客富翁系统
注册]");
System.out.println("请填写个人注册信息:");
System.out.print("用户名:");
userName =
input.next();
System.out.print("密码:");
password =
input.next();
//
获取4位随机数作为卡号
cardNumber =
(int)(Math.random()*(max-min))+min;
System.out.println("\n注册成功,请记好您的会员卡号");
System.out.println("用户名\t密码\t会员卡号");
System.out.println(userName
+ "\t" + password + "\t" + cardNumber);
isRegister =
true; // 注册成功,标志位设置为true
break;
case 2:
System.out.println("[奖客富翁系统
登录]");
if
(isRegister) { // 判断是否注册
//
3次输入机会
for (int i
= 1; i = 3; i++) {
System.out.print("请输入用户名:");
String
inputName = input.next();
System.out.print("请输入密码:");
String
inputPassword = input.next();
if
(userName.equals(inputName) password.equals(inputPassword)) {
System.out.println("\n欢迎您:"
+ userName);
isLogin =
true; // 登录成功,标志位设置为true
break;
} else if
(i 3) {
System.out.println("用户名或密码错误,还有"
+ (3 - i) + "次机会!");
} else
{
System.out.println("您3次均输入错误!");
}
}
} else
{
System.out.println("请先注册,再登录!");
}
break;
case 3:
System.out.println("[奖客富翁系统
抽奖]");
if
(!isLogin) { // 判断是否登录
System.out.println("请先登录,再抽奖!");
} else
{
//生成5个4位随机数字,并保存在数组中
int[]
luckynums = new int[5];
for(int i
= 0; i luckynums.length; i++){
luckynums[i] =
(int)(Math.random()*(max-min))+min;
}
System.out.print("请输入您的卡号:");
int
yourcard = input.nextInt();
int
i;
System.out.print("\n本日的幸运数字为:");
for (i = 0;
i luckynums.length; i++) {
System.out.print(luckynums[i]
+ " ");\
}
for (i = 0;
i luckynums.length; i++) {
if
(luckynums[i] == yourcard) {
System.out.println("\n恭喜!您是本日的幸运会员!");
break;
}
}
if (i ==
luckynums.length) {
System.out.println("\n抱歉!您不是本日的幸运会员!");
}
}
break;
default:
System.out.println("[您的输入有误!]");
break;
}
System.out.print("继续吗?(y/n):");
answer =
input.next();
System.out.println("");
} while
("y".equals(answer));
if
("n".equals(answer)) {
System.out.println("系统退出,谢谢使用!");
}
}
}
商场推出幸运抽奖活动的java初级代码编写
public class Lucky {
public static void main(String[] args){
System.out.println("请输入您的4位会员卡号:");
Scanner sc = new Scanner(System.in);
int number = sc.nextInt(); //接收用户从控制台输入的会员卡号,并保存在会员卡号变量中
int a = number/1000; //千位
int b = number%1000/100; //百位
int c = number%100/10; //十位
int d = number%10; //个位
if((a+b+c+d)20){
System.out.println("恭喜中奖!您是幸运客户");
}else{
System.out.println("谢谢参与!");
}
}
}
最基础的 没有异常判断 无限循环输入什么东西
java抽奖程序
我给你个比较简单的,,但是需要按照你的要求进行稍微的修改。。然后在main方法中去执行就可以了:
public class GoodLuck {
int custNo;
int i=1;
String answer;
String awardName;
public void LuckNo(){
Scanner input=new Scanner(System.in);
System.out.println("\n我行我素购物管理系统 幸运抽奖\n");
do{
// 需要的话请把随机数调整成你想要的范围(我这个是为了测试方便写的1
(~3的随机数,根据你的需要把下面的3换成你想要的数字就行了)
int num=(int)(Math.random()*3+1);
System.out.print("请输入会员卡号(4位整数):");
custNo=input.nextInt();
//百位数与随机数相同的为幸运者
int bai=custNo/100%10;
while(i==1){
if(custNo=1000custNo=9999){
break;
}
else{
System.out.println("\n会员号码输入有误,请重新输入:");
custNo=input.nextInt();
continue;
}
}
if(bai==num){
showAward();
System.out.print("\n卡号:"+custNo+"是幸运客户,获得"+awardName);
}else{
System.out.print("\n卡号:"+custNo+"\t谢谢您的支持!");
}
System.out.println("\n是否继续(y/n)");
answer=input.next();
while(i==1){
if(answer.equals("y")||answer.equals("n")){
break;
}else{
System.out.print("输入有误!请重新输入:");
answer=input.next();
continue;
}
}
}while(!answer.equals("n"));
}
public void showAward(){
int num=(int)(Math.random()*3+1);
if(num==1){
awardName="Mp3";
}
else if(num==2){
awardName="美的微波炉";
}
else{
awardName="美的电饭锅";
}
}
java抽奖活动需求的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Java抽奖、java抽奖活动需求的信息别忘了在本站进行查找喔。