/*
2017年3月13日10:27:18
java基础50道经典练习题 例43
Athor: ZJY
Purpose:
【程序43】
题目:求0—7所能组成的奇数个数。
*/
public class ProgramNo43_1
{
public static void main(String[] args) {
int count = 0;
int number = 8;
//一位数的奇数有
count += number/2;
//二位数的奇数有
count += (number-1)*number/2;
//三位数的奇数有
count += (number-1)*number*number/2;
//四位数的奇数有
count += (number-1)*number*number*number/2;
//五位数的奇数有
count += (number-1)*number*number*number*number/2;
//六位数的奇数有
count += (number-1)*number*number*number*number*number/2;
//七位数的奇数有
count += (number-1)*number*number*number*number*number*number/2;
System.out.println("[0-7]一共可以组成"+count+"个奇数!");
}
}
/*
2017年3月13日10:27:18
java基础50道经典练习题 例43
Athor: ZJY
Purpose:
*/
public class ProgramNo43_2
{
public static void main(String[] args){
int count = 0;
//声明由数字组成的数
int n = 8;
//一位数
count = n/2;
//两位数
count += (n-1)*n/2;
//三位数
count += (n-1)*n*n/2;
//四位数
count += (n-1)*n*n*n/2;
//五位数
count += (n-1)*n*n*n*n/2;
//六位数
count += (n-1)*n*n*n*n*n/2;
//七位数
count += (n-1)*n*n*n*n*n*n/2;
System.out.println("0-7所能组成的奇数个数:"+count);
}
}