彩票游戏
2015-08-19 17:43
861 查看
试了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"); } } }
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树
- [原创]java局域网聊天系统