排列组合c几几怎么用计算机算,排列组合A几几C几几的,有什么区别,都怎么计算来的?…
概率学公式
统计不重复的三位数
package cn.itcast.spring;
public class Test2 {
public static void main(String[] args) {
//不重复三位数
int num;
//个数
int count = 0;
//百位
for (int i = 1; i <= 9; i++) {
//十位
for (int j = 0; j <= 9; j++) {
//个位
for (int k = 0; k <= 9; k++) {
if (i != j && i != k && j != k) {
num = i * 100 + j * 10 + k;
System.out.println("num = " + num);
count++;
}
}
}
}
System.out.println("count = " + count);
}
}
计算10的阶乘输出
package cn.itcast.spring;
public class Test1 {
public static void main(String[] args) {
for (int counter = 0; counter <= 10; counter++) {
System.out.printf("%d! = %d\n", counter,
factorial(counter));
}
}
public static long factorial(long number) {
if (number <= 1) {
return 1;
} else {
return number * factorial(number - 1);
}
}
}
被5整除且不重复的三位数
package cn.itcast.spring;
public class Test3 {
public static void main(String[] args) {
//个位数是0的不重复三位数个数
int count0 = 0;
//个位数是5的不重复三位数个数
int count5 = 0;
//不重复三位数
int num;
for (int i = 1; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
if (i != j && i != 5 && j != 5) {
//个位数是5的不重复三位数
num = i * 100 + j * 10 + 5;
System.out.print(" " + num);
count5++;
}
}
}
System.out.println();
System.out.println("count5 = " + count5);
System.out.println("============================");
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i != j ) {
//个位数是0的不重复三位数
num = i * 100 + j * 10;
System.out.print(" " + num);
count0++;
}
}
}
System.out.println();
System.out.println("count0 = " + count0);
System.out.println("============================");
System.out.println("被5整除且不重复的三位数有" + (count0 + count5) + "个");
}
}