2
Targer - 需要算多少數與6位有左,右3位如何使用帶變量的方法?
什麼做的相同SUMM - 準備3種方法:
1日 - 計數SUMM從數字左3位 - 工程確定
private static int counterLeft3(int i) {
int digitCounter=0;
int summLeft3=0;
while (digitCounter!=3){
summLeft3=summLeft3+(i%10);
i=i/10;
digitCounter++;
}
return summLeft3;
}
2擋 - 從數右3位的計數SUMM - 工程確定
private static int counterRight3(int i) {
int summRight3=0;
int buffer;
int counter=0;
while (counter!=3){
summRight3=summRight3+(i%10);
i=i/10;
counter++;
}
buffer =i;
summRight3=0;
while (buffer!=0){
summRight3=summRight3+(buffer%10);
buffer=buffer/10;
}
return summRight3;
}
3-DR - 週期數的計數Q-TY - 八方通返回0 thnink - 我的錯誤thomthing這裏:
private static void summCounter() {
int counter=0;
for (int i=111110; i<1000000; i++){
if (counterRight3(i)==counterLeft3(i)){
}
counter = counter++;
}
System.out.println("Q-ty is " + counter);
}
調試 - 例如
第一種方法的結果
結果2擋的方法
問題 - 有什麼錯3擋的方法,爲什麼永諾只返回0和計數器從不增加?
改變 - 它的工作=)...感謝 – gbk
@Bki。不客氣:) –
此代碼需要放在'if'塊中。你有'if(...){} counter ++;'。需要成爲'if(...){counter ++; }'。 – jlordo