import java.util.Scanner; public class exam10 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("输入N:"); int n=sc.nextInt(); double sum=0; if(n==0){ System.out.println("被除数不能为0,请输入不为0的奇数或偶数"); } else if(n%2==0) { for(int i=2;i<=n;i+=2) { sum=sum+(float)1/i; } System.out.println("偶数和"+sum); } else { for(int i=1;i<=n;i+=2) { sum=sum+(float)1/i; } System.out.println("奇数和"+sum); } } }