我需要用Java创建一个程序来计算一个有4个房间的房子的面积。我不确定如何开始这个,因为我是java的新手。我可以选择房间的尺寸,因此根本不需要用户输入。据我所知,我可以使用长度*宽度来获得房间的平方英尺,然后将所有四个房间添加到房屋面积中。我只是不确定如何设置这一切。
public class sqfoot {
public static void main(String args[]){
double length, width;
room1
}
}
到目前为止,这就是我所拥有的一切。有人可以帮帮我吗?
答案 0 :(得分:0)
这是我提出的基本答案......我相信有很多简单的方法可以做到这一点。
public class sqfoot { public static void main(String [] args){
int House1_length1 = 14;
int House1_width1 = 20;
int House1_length2 = 10;
int House1_width2 = 18;
int House1_length3 = 10;
int House1_width3 = 17;
int House1_length4 = 17;
int House1_width4 = 14;
int House1_Area = ((House1_length1 * House1_width1) +
(House1_length2 * House1_width2) +
(House1_length3 * House1_width3) +
(House1_length4 * House1_width4));
System.out.println("House 1 square footage is " + ((House1_length1 * House1_width1) +
(House1_length2 * House1_width2) +
(House1_length3 * House1_width3) +
(House1_length4 * House1_width4)) + " Sq feet");
int House2_length1 = 13;
int House2_width1 = 21;
int House2_length2 = 12;
int House2_width2 = 17;
int House2_length3 = 11;
int House2_width3 = 15;
int House2_length4 = 13;
int House2_width4 = 14;
int House2_Area = ((House2_length1 * House2_width1) +
(House2_length2 * House2_width2) +
(House2_length3 * House2_width3) +
(House2_length4 * House2_width4));
System.out.println("House 2 square footage is " + ((House2_length1 * House2_width1) +
(House2_length2 * House2_width2) +
(House2_length3 * House2_width3) +
(House2_length4 * House2_width4)) + " Sq feet");
System.out.println("House 1 is larger than house 2 by " + (House1_Area - House2_Area) + " Sq feet");
}
}
答案 1 :(得分:-1)
使用以下内容完成代码:
import java.util.Scanner;
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
double len = 0;
double wid = 0;
System.out.print("Enter the length in feet:(##.##) ");
len = scan.nextDouble();
System.out.print("\nEnter the width in feet: (##.##) ");
wid = scan.nextDouble();
System.out.print("\n"+"The area is "+wid*len+" square feet.");
}