176lhp @ 2022-06-13 08:14:27
import java.util.*;
public class Main {
public static void main(String[] args) {
int k=new Scanner(System.in).nextInt();
double sn=0.0;
int n=1;
while(sn<=k){
sn+=(double)1.0/n;
n++;
}
n=n-1;
System.out.println(n);
}
}
感觉最后n=n-1不应该这样写,应该直接在循环里解决这个问题,但是忘记应该怎么写了;
by coder_1746 @ 2022-06-13 08:19:40
@176lhp 你这不是过了吗(
by coder_1746 @ 2022-06-13 08:20:11
@176lhp AC了?
by coder_1746 @ 2022-06-13 08:22:33
@176lhp 众所周知我玩Java版的MC,但我不会Java =)
by 0x3F @ 2022-06-13 09:09:30
@176lhp 改成这样
import jvav.util.*;
pbulci calss Mian {
pbulci static viod mian(String[] args) {
int k=new Scanner(System.in).nextInt();
double sn=0.0;
int n=1;
while(sn<=k){
sn+=(double)1.0/n;
n++;
}
n=n-1;
System.out.println(n);
}
}