题目要求
分析
看到有和我一样80分的,原因想必是用了do…while循环吧,其实这个题题意还是不明……
也可能就是我菜吧,能怎样?
好好读题吧,读不懂题就活该WA掉~~
第一次提交——WA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double position = scanner.nextDouble(), radius = scanner.nextDouble();
scanner.close();
double tempPosition = 0.0, nextRange = 7.0;
do {
tempPosition += nextRange;
nextRange *= 0.98;
} while (tempPosition < position - radius);
if (tempPosition + nextRange > position + radius) {
System.out.println("n");
} else {
System.out.println("y");
}
}
}
第二次提交——AC
放一下AC代码,Java版
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double position = scanner.nextDouble(), radius = scanner.nextDouble();
scanner.close();
double tempPosition = 0.0, nextRange = 7.0;
while (tempPosition < position - radius) {
tempPosition += nextRange;
nextRange *= 0.98;
}
if (tempPosition + nextRange > position + radius) {
System.out.println("n");
} else {
System.out.println("y");
}
}
}
后记
最近诸事不顺,也没怎么有时间写博客,水了个题,发一波~~
愿水逆退散,非去欧来~~