早教吧作业答案频道 -->其他-->
1、假设一条绳子长3000米,每天减去一半,请问需要花费几天的时间,使绳子的长度会短于五米.用JAVA程序
题目详情
1、假设一条绳子长3000米,每天减去一半,请问需要花费几天的时间,使绳子的长度会短于五米.用JAVA程序
▼优质解答
答案和解析
这个问题不难,给你写了一小段代码,改下包名,运行下
package 递归;
public class Line {
/**
* 天数
*/
private static int day = 0;
private static int limit = 5;
public static void main(String[] args) {
int length = 5000;
discount(length);
}
private static void discount(int length){
length = length/2;
day++;
System.out.println("今天是第"+day+"天,绳子今天的长度为:"+length);
if(length > limit){
discount(length);
}
}
}
package 递归;
public class Line {
/**
* 天数
*/
private static int day = 0;
private static int limit = 5;
public static void main(String[] args) {
int length = 5000;
discount(length);
}
private static void discount(int length){
length = length/2;
day++;
System.out.println("今天是第"+day+"天,绳子今天的长度为:"+length);
if(length > limit){
discount(length);
}
}
}
看了 1、假设一条绳子长3000米...的网友还看了以下:
小明生病了,下表是小明24小时的体温情况统计表.时间0时4时8时12时16时20时24时温度(℃) 2020-04-07 …
一次函数题当通话时间0≤T≤3时,付话费都是0.2元,当通话时间为5分钟时,付话费0.4元,随通话 2020-04-09 …
动物尸体内11C的含量每分钟递减3.5%,设动物死亡的时刻为0时,11C的含量为100%.(1)写 2020-04-25 …
一汽车额定功率为100kw,质量为1.0×10^4 kg,设阻力恒为车重的0.1倍,取g=10m/ 2020-05-16 …
某电子商务公司随机抽取l000名网络购物者进行调查,这1000名购物者2015年网上购物金额(单位 2020-06-08 …
0-100加速与0-200加速的区别为什么有的车0-100加速比另一台车快,而0-200加速的时间 2020-06-13 …
是一道关于微分中值定理的证明题,设函数f(x)在区间[0,3]上连续,在(0,3)内可导,且f(0 2020-07-13 …
∮1.一台洗衣机工作0.5小时,电流做功3.6×106焦,这台洗衣机消耗的电能是()焦.2.一个电 2020-07-18 …
阅读短文,回答问题:搜寻黑匣子MH370航班为马来西亚航空公司由吉隆坡飞往北京的航班,.起飞时间2 2020-07-29 …
某钟表每小时比标准时间慢3分钟,若在清晨6时30分与准确时间对准,则当天中午钟表指示时间为12时5 2020-07-30 …