Variable parameters and health conditions of Java classroom exercises

Source: Internet
Author: User

/*
Someone invited A,b,c,d,e,f 6 people to attend a meeting, these 6 people are a little strange, because they have a lot of requirements, known:
1) A/b two persons at least 1 persons attend the meeting;
2) A,e,f 3 out of 2 people attended the meeting;
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 are attending the Conference;
5) As long as 1 people attend the meeting of the C,d two persons;
6) If D does not go, then E decides not to go.
So what are the last few people who attended the meeting?
*/


The mutable parameter must be in the last item. When there is more than one variable parameter, there must be one that is not the last, so only one variable parameter is supported.

The written form of the variable parameter is as follows:
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 and after it can be;
3) The application of the variable parameter is actually the Java Virtual machine dynamically opened an array;

4) No other things can be added after three points.

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 persons at least 1 persons attend the meeting; rEturn false;} if (! ( Countgo (A1, A5, a6) = = 2) {//A,e,f 3 out of 2 people attend the meeting; 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 people attend the meeting; return false;} if (! ( Countgo (A3, a4) = = 1) {//C,d two also only 1 people attend the meeting; return false;} if (Countgo (a4) = = 0 && Countgo (a5) = = 1) {//If 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;}}






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Variable parameters and health conditions of Java classroom exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.