The topic is as follows, the code is as follows, hope each road great God generous enlighten.
Somewhere there are two strange villages, Zhang Zhuang people in Wednesdays, five lies, Li people in Tuesday, six lies. On other days they tell the truth.
One day, the field of Wang Congming came here, met two people, respectively, to their questions about the date. Two people said: "The day before yesterday is my days of lying." ”
If the two people asked were from Zhang Zhuang and Li Village, what day is it?
The following is a way to traverse, self-feeling is not very good, do not know whether the logical derivation of the way to obtain the final result.
1 Packagejiang.test;2 /**3 * Somewhere there are two strange villages, the people of Zhang Zhuang in Wednesdays, five lies, Li people in Tuesday, six lies. On other days they tell the truth. 4 * One day, the foreign Wang Congming came here and met two people, and asked them about the date respectively. Two people said: "The day before yesterday is my days of lying." "5 * If the two people asked were from Zhang Zhuang and Li Village, what day is it? 6 * @authorAdministrator7 *8 */9 Public classWhatday {Ten One Public Static voidMain (string[] args) { A BooleanIsLay =true; - for(intBeyes = 1;beyes <= 7;beyes++){ - intToday = (beyes+2)%7; theString Zhangzhang = "Zhang"; -String licun = "Li"; - if(Isright (Zhangzhang,beyes,islay) &&isright (Licun,beyes,islay)) { -SYSTEM.ERR.PRINTLN ("This day is the week" +today); + } - } + } A /** at * Logic is correct, return true - * @paramUser - * @paramBeyes - * @paramIsLay - * @return - */ in Public Static BooleanIsright (String user,intBeyes,BooleanIsLay) { - intToday = (beyes+2)%7; to BooleanBelay =islying (user,beyes); + BooleanLay =islying (user,today); - if(lay&&!belay==IsLay) { the return true; *}Else if(!lay&&belay==IsLay) { $ return true;Panax Notoginseng}Else - return false; the } + /** A * Whether to lie the * @paramUser + * @param Day - * @return $ */ $ Public Static BooleanIslying (String user,intDay ) { - if(User.equals ("Zhang")){ - if(day==1| | day==3| | Day==5) the return true; -}Else if(User.equals ("Li")){Wuyi if(day==2| | day==4| | Day==6) the return true; - } Wu return false; - } About}
A logical question (today's Day of the week) causes the thought