import java.io.IOException; import java.util.Scanner; public class Sum { public static void main(String[] args) throws IOException { try { System.out.println("请输入的i的值!"); Scanner input = new Scanner(System.in); int i = input.nextInt(); System.out.println("求和的值为:" + sum(i)); } catch (Exception ex) { System.out.println("输入的i为整数!"); } } public static double sum(int i) { double result = 0; int j; for (j = i; j > 0; j--) { result = result + ((double) j / (2 * (double) j + 1)); } System.out.println("输入的整数要求为正!"); return result; } }
递归求和m(i)=i/(i*2+1)