我是java新手,需要幫助。我的while循環不起作用。它不會執行除count之外的其他任何操作。while循環沒有執行
對於這個問題,我需要做的是具有突變和附件的方法分數類。然後,我必須使分子和分母最低形式,所以我使用while循環通過使用模塊來查找最大公約數。任何其他評論家也表示感謝。
public class Fraction {
private int numerator;
private int denominator;
public Fraction(){
}
public Fraction(int num, int den){
this.numerator = num;
this.denominator = den;
}
public void setNumerator(int numerator){
this.numerator = numerator;
}
public void setDenominator(int denominator){
this.denominator = denominator;
}
public double divided(){
double divide = (double)this.numerator/this.denominator;
return divide;
}
public String printFraction(){
int numerator = greatestCommmonNumetaror();
return "";
}
private int greatestCommmonNumetaror(){
int count = 1;
int first;
int mod;
while(count != this.numerator){// need help with this
mod = this.numerator%count;
if(mod != 0){
first = count;
if(first < count){
first = count;
}
}
count++;
}
return 1;
}
}
你說的意思是「它不執行除算什麼。」 – Shahzeb
放入一些'println's,這樣你就知道運行的是什麼。 –
我不確定你的while循環試圖實現什麼。你設置了一堆變量,但似乎並沒有使用它們,最後你只返回「1」。你能用文字來描述該算法試圖做什麼嗎? –