0-7组成的奇数数量
1位数: 1, 3, 5, 7(4种)
2位数: 7*4
3位数: 7*8*4
4位数: 7*8*8*4
…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
public class { public static void main(String[] args) { int count = 0; int sum = 0; for (int i=0; i<8; i++) { if (i == 0) { count = 4; } else if (i == 1) { count *= 7; } else if (i >= 2) { count *= 8; } sum += count; System.out.println("组成"+(i+1)+"位数时有"+count+"种组合方式"); } System.out.println("共有"+sum+"种组合方式"); } }
|
————–43/50————–
近期评论