彩票游戏

试了N多次都是只能猜对一个数字,犹如我这坎坷的半辈子一样,永远都只能老老实实的靠实力说话,投机取巧什么的似乎与我无缘。

/*
Enter your lottery pick (three digits): 124
The lottery number is : 626
Match one digit: you win $1,000
Enter your lottery pick (three digits): 661
The lottery number is : 369
Match one digit: you win $1,000
Enter your lottery pick (three digits): 357
The lottery number is : 790
Match one digit: you win $1,000
Enter your lottery pick (three digits): 112
The lottery number is : 792
Match one digit: you win $1,000
*/
import java.util.Scanner;

public class Lottery {
    public static void main(String[] args) {        
        Scanner input = new Scanner(System.in);

        final int POINT = 10;
        int guess;          
        int lotteryDigit1, lotteryDigit2, lotteryDigit3;
        int lottery, lottery1, lottery2, lottery3;

        for(;;) {
            lottery = (int)(Math.random() * 1000);
            System.out.print("Enter your lottery pick (three digits): ");
            guess = input.nextInt();

            lotteryDigit3 = guess % POINT ;
            lotteryDigit2 = guess / POINT % POINT;
            lotteryDigit1 = guess / POINT / POINT;

            lottery1 = lottery / POINT / POINT;
            lottery2 = lottery / POINT % POINT;
            lottery3 = lottery % POINT;

            System.out.println("The lottery number is : " + lottery);

            if (lottery == guess)           
                System.out.println("Exact match: you win $10,000");
            else if ((lottery1 == lotteryDigit2) && (lottery2 == lotteryDigit3) && (lottery3 == lotteryDigit1))
                System.out.println("Match all digits: you win $3,000");
            else if ((lottery1 == lotteryDigit3) && (lottery2 == lotteryDigit1) && (lottery3 == lotteryDigit2))
                System.out.println("Match all digits: you win $3,000");
            else if ((lottery1 == lotteryDigit1) ^ (lottery2 == lotteryDigit2) ^ (lottery3 == lotteryDigit3))
                System.out.println("Match one digit: you win $1,000"); 
            else if ((lottery1 == lotteryDigit2) ^ (lottery2 == lotteryDigit3) ^ (lottery3 == lotteryDigit1))
                System.out.println("Match one digit: you win $1,000");
            else if ((lottery1 == lotteryDigit3) ^ (lottery2 == lotteryDigit1) ^ (lottery3 == lotteryDigit2))
                System.out.println("Match one digit: you win $1,000"); 
        }
    }   
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值