愤怒的小鸟从A车出发,时速50米/秒,撞向B车,
然后返回去撞A车,再返回去撞B车,如此往复....
两火车在相距1米处停车。
问:这期间愤怒的小鸟撞 B 车多少次? 9 次
注意:需要提交的是一个整数(表示撞B车的次数),不要填写任何其它内容。
public class 愤怒小鸟01
{
// 计数变量; 递归问题
static int i = 0;
static int n = 0;
public static void main(String[] args)
{
f(1000);
System.out.println(n);
}
static double f(double length)
{
double t = length/60;
length = length - 10*2*t;
if (length<=1)
{
return 0;
}
if (i%2==0)
{
n++;
}
i++;
return f(length);
}
}