public class Test_1000以内的水仙花数 {
public static void main(String[] args) {
for(int i = 100; i < 1000 ; i++){
int a = i%10;//个位
int b = i%100/10;//十位
int c = i/100;//百位
int sum = (a*a*a)+(b*b*b)+(c*c*c);
if(sum == i){
System.out.print(sum+"\n");
}
}
}
}
public class Test_改写水仙花 {
public static void main(String[] args) {
for (int i = 100; i < 1000; i++) {
if (isNarcissus(i)) {
System.out.println(i);
}
}
}
private static boolean isNarcissus(int i) {
int a = i % 10;// 个位
int b = (i % 100) / 10;// 十位
int c = i / 100;// 百位
return (i == a * a * a + b * b * b + c * c * c);
}
}
public class Test_九九乘法表 {
public static void main(String[] args) {
for(int i = 1 ;i <= 9 ; i++){
for(int j = 1 ; j <= i ; j++){
System.out.printf("%d*%d=%d\t",i,j,i*j);
}
System.out.println();
}
}
}
public class Test_常数e {
public static void main(String[] args) {
double e = 1;
int n = 1;
double fraction;
do{
fraction = 1.0/factorial(n);
e += fraction;
n ++;
}while(fraction > 1e-8);
System.out.print(e);
}
private static int factorial(int n) {
int sum = 1;
for(int i =1;i<=n;i++){
sum *= i;
}
return sum;
}
}
public class Test_亲密对数 {
public static void main(String[] args) {
for (int i = 1; i < 1000; i++) {
int j = factor(i);
if (factor(j) == i && i < j) {
System.out.printf("%4d %4d\n", i, j);
}
}
}
private static int factor(int i) {
int sum = 0;// 因子和
for (int n = 1; n <= i / 2; n++) {
if (i % n == 0) {
sum += n;
}
}
return sum;
}
}
public class Test_累加和 {
public static void main(String[] args) {
double mole = 1;//分子
double deno = 2;//分母
double denos = 0;//保留分母
double sum = 0;
for(int i = 1;i <= 20;i++){
sum += mole/deno;
denos = deno+mole;
mole = deno;
deno = denos;
}
System.out.print(sum);
}
}
public class Test_1000以内的水仙花数 { public static void main(String[] args) { for(int i = 100; i < 1000 ; i++){ int a = i%10;//个位 int b = i%100/10;//十位 int c = i/100;//百位 int sum = (a*a*a)