# 猜生日 Java小游戏

set1：1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31

set2：2 3 6 7 10 11 14 15 18 19 22 23  26 27 30 31

set3：4 5 6 7 12 13 14 15 20 21 22 23  28 29 30 31

set4：8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31

set5：16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

import javax.swing.JOptionPane;

public class GuessBirthday{
public static void main(String[] args) {
String set1=
" 1  3  5  7\n"+
" 9 11 13 15\n"+
"17 19 21 23\n"+
"25 27 29 31";

String set2=
" 2  3  6  7\n"+
"10 11 14 15\n"+
"18 19 22 23\n"+
"26 27 30 31";

String set3=
" 4  5  6  7\n"+
"12 13 14 15\n"+
"20 21 22 23\n"+
"28 29 30 31";

String set4=
" 8  9 10 11\n"+
"12 13 14 15\n"+
"24 25 26 27\n"+
"28 29 30 31";

String set5=
"16 17 18 19\n"+
"20 21 22 23\n"+
"24 25 26 27\n"+
"28 29 30 31";

int day=0;

//Prompt the user to answer questions
"Is your birthday in these numbers?\n"+set1);

day+=1;

"Is your birthday in these numbers?\n"+set2);

day+=2;

"Is your birthday in these numbers?\n"+set3);

day+=4;

"Is your birthday in these numbers\n"+set4);

day+=8;

"Is your birthday in these numbers?\n"+set5);

day+=16;

day+"!");
}
} 

 十进制 二进制 1 00001 2 00010 3 00011 … 19 10011 … 31 11111

30的二进制数为11111，所以它在Set1~Set5中都有出现。

posted @ 2016-08-27 20:47 左昱_leftshine 阅读(...) 评论(...) 编辑 收藏