0
첫 번째 코드는 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);
}
}
어. 변수로'l'을 사용하지 마십시오. 어떤 글꼴에서는 글자 그대로 차이를 알 수 없습니다. –
참. 다행스럽게도 Github은 숫자 리터럴에 다른 색상을 사용했습니다. :) – helospark