已知长方型的周长和面积 求长和宽 代码怎么去定义呢
public class Area {
public static void main(String[] args){
double (a + b)*2=perimeter;
double perimeter =4.39;
double area =0.57;
第一个double 报错 我怎么在代码上定义长宽
public class Area {
public static void main(String[] args){
double (a + b)*2=perimeter;
double perimeter =4.39;
double area =0.57;
第一个double 报错 我怎么在代码上定义长宽
2017-08-18
public class Area{
public static void main(String args[])
{
double a1,a2,b1,b2;//假定a1、a2为长、b1、b2为宽
double i;//i为Δ
double perimeter=4.39;
double area=0.57;
i = (perimeter*perimeter)-4*area;
if(i >= 0)
{
a1 = ((-perimeter) + Math.sqrt(i)) / ( 2 * area );
a2 = ((-perimeter) - Math.sqrt(i)) / ( 2 * area );
b1 = area / a1;
b2 = area / a2;
System.out.println("第一种情况:长为"+a1+" "+"宽为"+b1);
System.out.println("第二种情况:长为"+a2+" "+"宽为"+b2);
}
else System.out.println("长、宽均不存在");
}
}
举报