public static void main(String[] args) {
int sum = 0;
for (int a = 1;a <= 100 ;a++ ) {
//sum = sum + a; //求1-10的和用
if (a % 2 == 0) {
sum = a + sum;
} //求偶数和用
if (a % 2 != 0) {
sum = sum + a;
} //求奇数和用
}
System.out.println(sum);
//打印水仙花数
for (int a = 100;a <= 999 ;a++ ) {
int ge = a % 10;
int shi = a / 10 % 10;
int bai = a / 10 / 10 % 10;
if (ge*ge*ge + shi*shi*shi + bai*bai*bai == a) {
System.out.println(a);
}
}
//统计水仙花数
int num = 0;
for (int a = 100;a <= 999 ;a ++ ) {
int ge = a % 10;
int shi = a /10 % 10;
int bai = a /10 / 10 % 10;
if (ge*ge*ge + shi*shi*shi + bai*bai*bai == a) {
num++;
}
}
System.out.println(num);
|
|