彩票中奖
简化题目:输入三个数,若顺序和数字相同中10000元(美金),若只是顺序不同数字相同中3000,
若只有一个匹配位置的数字相同中1000,做出这个抽奖程序!
===============================================
简化题目:输入三个数,若顺序和数字相同中10000元(美金),若只是顺序不同数字相同中3000,
若只有一个匹配位置的数字相同中1000,做出这个抽奖程序!
===============================================
package com.aiqiongdiao;
import java.util.Scanner;
class Test{
/**
* 3个随机数:
* 顺序:10000
* 匹配:3000
* 一个中:1000
*/
public static int one(int num,int temp){
if(temp==num){
return 1;
}
else{
return 0;
}
}
public static int two(int a[],int temp,int i,int temp2){
if(temp==0){ //temp的边界
return two(a,temp2,i+1,temp2); //返回数值temp2
}
if(i>2){ //数组的边界
return 0;
}
if(a[i]==temp%10){
return two(a,temp2,i+1,temp2)+1; //返回值+1
}else{
return two(a,temp/10,i,temp2);
}
}
public static int three(int a[],int temp,int i){
if(i<0||temp==0){
return 0;
}
if(a[i]==temp%10){
return 1;
}
else{
return three(a,temp/10,i-1); //此处不能自减
}
}
public static void main(String[] args) {
/**
* 获取数据
*/
Scanner input =new Scanner(System.in);
System.out.print("请输入三个数:");
int a[]=new int[3];
a[0]=input.nextInt();
a[1]=input.nextInt();
a[2]=input.nextInt();
int num=a[0]*100+a[1]*10+a[2];
int temp = (int) ( 899 * Math.random() + 100); //随机的temp
// int temp=123;
int temp2=temp;
System.out.println("随机数是:"+temp);
/**
* 获奖函数
*/
if(one(num,temp)==1){
System.out.println("尼玛,都10000$了");
}
if((two(a,temp,0,temp2))==3){
System.out.println("糟了,有3000$了");
}else{
if(three(a,temp,2)==1){ //要让中一个和中三个平行开,避免重复
System.out.println("惨了,有1000$了");
}else{
System.out.println("太好了,啥鸟都没有");
} }
}
}