-1
我需要從用戶獲取三個整數,然後找到可以被第三個整數(模數)整除的兩個數字(startInt和endInt)之間的數字,然後將所有可分割的數字打印到一個jTextField中。我確信有一個簡單的解決方案,我錯過了,但我不能爲我的生活找出我在做什麼。如何找到可以被第三個整數整除的整數之間的所有數字?
這裏是我的代碼:
private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {
int startInt, endInt, modulus;
startInt = Integer.parseInt(startTextField.getText());
endInt = Integer.parseInt(endTextField.getText());
modulus = Integer.parseInt(modulusTextField.getText());
int intDistance = endInt - startInt;
for (int loopCounter; loopCounter <= intDistance; loopCounter++) {
}
}
歡迎來到Stack Overflow!一般來說,這裏同意[你不應該在你的帖子中使用問候或稱呼](http://meta.stackoverflow.com/questions/276033/pointless-question-edit/276037#276037)。他們妨礙我們讀者找出真正的問題。這次我爲你編輯了它們。 – 2014-11-04 18:41:37
'int loopCounter'需要一個初始值 - 'int loopCounter ='...你想從什麼開始? –
ajb
2014-11-04 18:41:51
在Java中有一個'%'運算符,它可以在除數時給你餘數。你想從一個數字循環到另一個數字,尋找何時'loopCounter%modulus == 0'。 – azurefrog 2014-11-04 18:41:59