拖延的毛病还是很严重。。。
这题转化过来其实就是求第几天扩展的圈会覆盖到房子的坐标,那么可以用半径来做,也可以用面积来做,更喜欢乘法的我选择了用面积做:
import java.text.DecimalFormat;
import java.util.Scanner;
public class testOne {
public static void main(String[] arg)
{
final double pi = 3.1415926;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
double x,y,s;
double result;
for(int i = 1; i <= n; i++){
x = sc.nextDouble();
y = sc.nextDouble();
s = pi * (x * x + y * y) / 2;
result = Math.ceil(s / 50);
System.out.printf("Property %d: This property will begin eroding in year %d.",i,(int)result);
System.out.println();
}
System.out.print("END OF OUTPUT.");
sc.close();
}
}
对于新接触java来说,这题使用了final常亮定义PI也就是圆周率;
还是用了Math.ceil函数来向上求整,java求整有四个函数,可自行google;
还有就是根据输出要求(int)result强制转化了原为double型的result。

343

被折叠的 条评论
为什么被折叠?



