大家好,又见面了,我是全栈君。
今天的题目是I Think I Need a Houseboat
如下:
Description
After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the X axis. Locations below the X axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)
Input
Output
Sample Input
2
1.0 1.0
25.0 0.0
Sample Output
Property 1: This property will begin eroding in year 1.
Property 2: This property will begin eroding in year 20.
END OF OUTPUT.
Hint
2.This problem will be judged automatically. Your answer must match exactly, including the capitalization, punctuation, and white-space. This includes the periods at the ends of the lines.
3.All locations are given in miles.
代码如下:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class IThinkINeedaHouseboat {
public static void main(String args[]){
double PI = 3.1415926;
int year = 1;
float area = 0;
int year_count = 0;
Scanner in = new Scanner(System.in);
int all = in.nextInt();
int count = all * 2;
List<Float> list = new ArrayList<Float>();
while(count > 0){
count--;
list.add(in.nextFloat());
}
for(int i = 0; i<list.size(); i = i + 2){
year_count ++;
area = (float) (PI*(list.get(i) * list.get(i) + list.get(i + 1) * list.get(i + 1))/2);
for(year = 1; year * 50 < area; year ++){
}
System.out.println("Property "+ year_count + ": This property will begin eroding in year " + year + ".");
}
System.out.println("END OF OUTPUT.");
}
}
作者:jason0539
微博:http://weibo.com/2553717707
博客:http://blog.csdn.net/jason0539(转载请说明出处)
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/121384.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...