/*
6 people were invited to participate in a meeting, these 6 people are a little strange a,b,c,d,e,f. Since they have very many requirements, known:
1) A/b two persons have at least 1 participants to participate in the Conference;
2) A,e,f 3 out of 2 people participated in the conference.
3) B and C Two people unanimously decided that either two people go, or neither of them go;
4) Only 1 of the A,d two participated in the conference.
5) Only 1 people in the C,d two will participate in the Conference;
6) If D does not go, then E also decides not to go.
So what are the last few people who have joined the meeting?
*/
The variable parameter must be in the last item.
When a variable number of variables is more than one. There will be one not the last. So there is only one variable parameter supported.
The written form of a variable number of parameters such as:
void A (Boolean a,int ... args) {method body}
1) must be three points;
2) ... Between the variable type and the variable name, there are no spaces before or after it is possible.
3) The application of variable parameters is actually an array of Java virtual machines dynamically opened;
4) No other things can be added after three.
Package Cn.hncu.p37.meeting;public class Meeting1 {public static void main (string[] args) {for (int a1 = 1; A1 <= 2; A1 + +) {for (int a2 = 1; A2 <= 2, a2++) {for (int a3 = 1, A3 <= 2; a3++) {for (int a4 = 1, A4 <= 2; a4++) {for (int A5 = 1; A5 <= 2; a5++) {for (int a6 = 1; A6 <= 2; a6++) {if (ok (A1, a2, A3, A4, A5, a6)) {System.out.println ("a1--" +a1+ "\na2--" +a2+ "\na3 --"+a3+" \na4--"+a4+" \na5--"+a5+" \na6--"+a6"; break;}}}}} Similar to the above 6 for//for (int i = 0; I <=, i++) {//binary means six persons (000000 ~ 111111) Go or not 1 means go, 0 means do not go//a = ((i & 1) = = 0)? 0:1;//b = ((I & 2) = = 0)?0:1;//c = ((i & 4) = = 0)? 0:1;//d = ((I & 8) = = 0)? 0:1;//e = ((i & 16) = = 0)? 0:1;//f = ((I & 32) = = 0)? 0:1;//if (Fun (A, B, C, D, E, F)) {//system.out.println ("a=" + A + "b=" + B + "c=" + C + "d="//+ D + "e=" + E + "f=" + f);//}//}}private static Boolean ok (int a1, int a2, int a3, int A4, int a5, int a6) {if (! ( Countgo (A1, A2) >= 1) {//A, b Two people have at least 1 participants to participate in the conference. return false;} if (! ( Countgo (A1, A5, a6) = = 2) {//A,e,f 3 out of 2 participants participated; return false;} if (! ( Countgo (A2, a3) = = 2 | | Countgo (A2, a3) = = 0) {//B and C Two people unanimously decide that either of them will go, or neither of them will go; return false;} if (! ( Countgo (a1, a4) = = 1) {//A,d two only 1 participants participated in the conference. return false;} if (! ( Countgo (A3, a4) = = 1) {//C,d two only 1 people will participate in the conference; return false;} if (Countgo (a4) = = 0 && Countgo (a5) = = 1) {//assuming d does not go, then E decides not to go. return false;} return true;} private static int Countgo (int ... mee) {int count = 0;for (int me:mee) {if (me = = 1) {count++;}} return count;}}
The variable parameters and health conditions of Java classroom exercises