1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 double sum = 0; 6 7 for(int i = 1; i <= 50000; i++) 8 sum += 1.0 / (i * 1.0); 9 System.out.println("From left to right, sum is " + sum); 10 11 sum = 0; 12 13 for(int i = 50000; i >= 1; i--) 14 sum += 1.0 / (i * 1.0); 15 System.out.println("From right to left, sum is " + sum); 16 } 17 }
时间: 2024-10-10 13:16:54