已知注水管需要3小时注满水,排水管需要5小时排空,同时打开,问多长时间注满水?
public class affusion {
public static void main(String[] args)
{
double v=1.0;
double inspeed=3.0;
double outspeed=5.0;
double needtime;
needtime=v/(v/inspeed-v/outspeed);
System.out.print("注满水所需时间为"+needtime);
}
}
运行结果:
9.输入注水管单独注满水时间,排水管单独排空水时间,问:同时打开,多长时间注满水?
import java.io.*;
public class affusion{
public static void main(String[] args) throws IOException
{
double v=1.0;
double inspeed;
BufferedReader din=new BufferedReader(new InputStreamReader(System.in));
System.out.print("inspeed:");
inspeed=Float.parseFloat(din.readLine());
double outspeed;
BufferedReader din1=new BufferedReader(new InputStreamReader(System.in));
System.out.print("outspeed:");
outspeed=Float.parseFloat(din.readLine());
if(inspeed>=outspeed)
System.out.print("输入数据有误");
else{
double needtime;
needtime=v/(v/inspeed-v/outspeed);
System.out.print("注满水所需时间为"+needtime);
}
}
}
运行结果:
10.同一个笼子里,有一些鸡和兔子,如果这些鸡和兔子一共有40个头,100只脚,请问笼内有鸡和兔各多少只?
public class Hyik {
public static void main(String[] args)
{
int chicken,rabbit,head=40,foot=100;
chicken=(head*4-foot)/2;
rabbit=(foot-head*2)/2;
System.out.print("鸡有"+chicken+"只"+","+"兔子有"+rabbit+"只");
}
}
运行结果:
以上代码均已通过编译连接