package javafirst; public class HomeWork { public static void main(String[] args){ System.out.println("输出一个菱形!"); for(int i = 0; i < 5; i ++){ for(int j = 5; j > i + 1; j--){ System.out.print(" "); } for(int k = 0; k < 2*i + 1; k++){ System.out.print("*"); } System.out.println(); } for(int i = 4;i > 0; i--){ for(int k = 4; k >= i; k--){ System.out.print(" "); } for(int j = 0;j < 2*i - 1; j++){ System.out.print("*"); } System.out.println(); } System.out.println("\n\n输出阶乘倒数之和!"); double sum =0 ,sum2 = 1; int i = 1; while(i <= 20){ sum2 *= i++; sum += 1 / sum2; } System.out.println(sum); } }
时间: 2024-10-22 08:19:19