Tri-Color Ball problem

Source: Internet
Author: User

Tri-Color Ball problem

If you put 12 balls in one pocket, 3 red, 3 yellow, 6 green, choose 8 from any of them, how many different combinations do you ask?

1: Analysis of the problem

The red ball can have 4 possibilities: 0, 1, 2, 3

The yellow ball can have 4 possibilities: 0, 1, 2, 3

Green balls can have 7 possibilities: 0, 1, 2, 3, 4, 5, 6

We just need to be poor and give every possible situation.

 PackageTri-color ball;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {intRed,yellow,green;//stores the number of red, yellow, and green balls        intN; System.out.println ("Three-color ball problem solving!" \ n "); System.out.println ("Please enter the number of red balls as:"); Scanner input=NewScanner (system.in); Red=Input.nextint (); System.out.println ("Please enter the number of yellow balls:"); Yellow=Input.nextint (); System.out.println ("Please enter the number of green balls:"); Green=Input.nextint (); System.out.println ("Please enter the number of balls to be removed first:"); N=Input.nextint (); //solvingThreeball (red,yellow,green,n); }    Private Static voidThreeball (intRedintYellowintGreenintN) {inti,j,k; System.out.println ("There are a total of the following possibilities!" \ n "); System.out.printf ("\ t red ball \ t yellow ball \ t Green Ball");  for(i=0;i<=red;i++)        {             for(j=0;j<=yellow;j++)            {                 for(k=0;k<=green;k++)                {                    if(I+j+k = =N) {System.out.printf ("\t%d\t%d\t%d\n", i,j,k); }                }            }        }            }}

Results:

Three-color ball problem solving!

Please enter the number of red balls as:
3
Please enter the number of yellow balls:
3
Please enter the number of green balls:
6
Please enter the number of balls to be removed first:
8
There are a total of the following possibilities!

Red ball yellow ball green ball 026
035
116
125
134
206
215
224
233
305
314
323
332

Tri-Color Ball problem

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.