+ = 다른 결과를 생성합니다 아래 코드를 참조하십시오 ... 임시 코드가 올바르게 작동하지 않는 코드는 Java 응용 프로그램을 생성하여 디버깅 할 수 있습니다.Java + = 연산자 "특정 숫자 다음에 추가 중지"
public long JavaStopsAdding(int treeHeight) {
long cars = 0;
long cars1 = 0;
int i = 0;
while (treeHeight - i >= 0) {
long temp = 0;
if (treeHeight - i == 0) {
cars += 1;
cars1 += 1;
break;
}
// working code start
temp = (long) ((Math.pow(2,treeHeight- i))/2);
cars1 += temp;
System.out.print("temp " + (treeHeight- i) + " cars " + cars1 +"\n");
// working code END
// NON working code Start
cars += ((Math.pow(2,treeHeight- i))/2);
System.out.print("temp " + (treeHeight- i) + " cars " + cars + "\n");
// NON working code END
i += 2;
}
return cars;
}
정류장이란 무엇입니까? i/p 및 예상 o/p는 무엇입니까? – NINCOMPOOP
무엇이 문제입니까? 너 뭐하려고? –
당신은'cars + = (long) ((Math.pow (2, treeHeight-i))/2);'시도 했습니까? –