一共13种组合
public class Ball {
public static void main(String[] args) {
int count = 0;
for(int red = 0; red <= 3; red++){
for(int white = 0; white <= 3; white++){
int black = 8 - red - white;
if(black <= 6){
count++;
System.out.println("(red, white, black): " + red + ", " + white + ", " + black);
}
}
}
System.out.println("Total " + count + " ways to get the ball!");
}
}
----------------
(red, white, black): 0, 2, 6
(red, white, black): 0, 3, 5
(red, white, black): 1, 1, 6
(red, white, black): 1, 2, 5
(red, white, black): 1, 3, 4
(red, white, black): 2, 0, 6
(red, white, black): 2, 1, 5
(red, white, black): 2, 2, 4
(red, white, black): 2, 3, 3
(red, white, black): 3, 0, 5
(red, white, black): 3, 1, 4
(red, white, black): 3, 2, 3
(red, white, black): 3, 3, 2
Total 13 ways to get the ball!