-2
public static void main(String... args){
Scanner sc = new Scanner(System.in);
int count =0;
int a= sc.nextInt();
int b =sc.nextInt();
if(a>b){
//int count =0;
for(int i =1;i<=a;i++){
if(a/i == 0 && b/i == 0){
count++;
System.out.println(count);
}
}
}else if(a<b){
//int count =0;
for(int i=1;i<=b;i++){
if(a/i == 0 && b/i == 0){
count++;
System.out.println(count);
}
}
}
}
- 我沒有得到任何輸出是什麼錯誤?
- 我想從用戶那裏獲得輸入信息,然後找出共同因素的數量。
歡迎來到SO!你應該嘗試修復你的格式,特別是代碼縮進。你絕對不應該在一行上使用多個大括號,因爲它使得看到代碼塊變得更困難。如果您不知道這是個好習慣,請閱讀[Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)。 – Aurora0001
你需要檢查/學習基礎數學:是否有任何數字,你可以將它們分開並得到0作爲答案? 'a/i = 0' - >'a = 0 * i' - >'a = 0'。 –
@MarcB我當時也在想,但它是整數除法,所以如果除法結果數小於1,那麼結果將爲0.雖然在這個程序中,自循環條件以來永遠不會發生。 –