代码
import java.util.Scanner;
public class sum {
public static void main(String[] args) {
// TODO Auto-generated method stub
sum s = new sum();
s.Sum();
}
void Sum(){
Scanner s = new Scanner(System.in);
int a = s.nextInt();
double d = 0;
if(a % 2 == 0){
for(double i = 2;i <= a;i += 2){
d += 1 / i;
}
}else{
for(double i = 1;i <= a;i += 1){
d += 1 / i;
}
}
System.out.printf("%.8f", d);
}
}
C:\Users\Administrator\Desktop\a.png |