第一个代码是我自己在Lynda.com上的作业。第二个代码是教师对该作业的回答。除了这里和那里的几个字,我还没有找到逻辑或方程式的任何差异,但第一个代码给出一个数字作为解决方式低于第二个给出的解决方案。
public class SimpleCalculation {
public static void main(String[] args) {
// Declare all variables
// Ask for the house length, width, and height
// Ask for the number and size of windows
// Ask for the number and size of doors
// Calculate total surface area to be painted
double w, l, h;
double numWin, winWidth, winHeight;
double numDoors, doorWidth, doorHeight;
double surfaceArea;
Scanner in = new Scanner(System.in);
System.out.println("Please enter the width, length and height of your house: ");
w = in.nextDouble();
l = in.nextDouble();
h = in.nextDouble();
System.out.println("Please enter the number of windows, width and height: ");
numWin = in.nextDouble();
winWidth = in.nextDouble();
winHeight = in.nextDouble();
System.out.println("Please enter the number of doors, width and height: ");
numDoors = in.nextDouble();
doorWidth = in.nextDouble();
doorHeight = in.nextDouble();
surfaceArea = (w * h * 2 + 1 * h * 2) - (numWin * winWidth * winHeight +
numDoors * doorWidth * doorHeight);
System.out.println("The total paintable surface area is: "+ surfaceArea);
}
}
public class SimpleCalculation_Final {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double w, l, h;
double numWin, winWidth, winHeight;
double numDoors, doorWidth, doorHeight;
double surfaceArea;
System.out.println("Please enter the width, length and height of "
+ "the house to be painted");
Scanner in = new Scanner(System.in);
w = in.nextDouble();
l = in.nextDouble();
h = in.nextDouble();
System.out.println("Please enter the number of windows, width and height");
numWin = in.nextDouble();
winWidth = in.nextDouble();
winHeight = in.nextDouble();
System.out.println("Please enter the number of doors, width and height");
numDoors = in.nextDouble();
doorWidth = in.nextDouble();
doorHeight = in.nextDouble();
surfaceArea = (w * h * 2 + l * h * 2) - (numWin * winWidth * winHeight +
numDoors * doorWidth * doorHeight);
System.out.println("The total paintable surface area is: "+ surfaceArea);
}
}
答案 0 :(得分:0)
我发现的一件事是你有1 * h * 2
,而第二个代码有l * h * 2
(第一个是一个,第二个是小写的L)。
我没有检查过您的整个代码,可能还有其他差异。