1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
僅當(dāng)您的 value1 (A) 大于或等于其他兩個(gè)時(shí),您的數(shù)字構(gòu)造函數(shù)才會(huì)執(zhí)行任何操作。如果不是,則會(huì)將小、中和大保留為 0。
編輯:在這里擴(kuò)展答案,因?yàn)樗雌饋砀蓛?。所以在你的?shù)字構(gòu)造函數(shù)中
public Numbers(double A, double B, double C)
{
if(A>=B && A>=C)
{
large = A;
if(B>=C && B<=A)
{
medium = B;
small = C;
}
else
{
medium = C;
small = B;
}
}
}
只有一個(gè)主 if 語句檢查 A 是否最大,其余的都嵌套在其中。您還需要一個(gè) if 語句來判斷 B 或 C 是否最大。
public Numbers(double A, double B, double C)
{
if(A>=B && A>=C)
{
large = A;
if(B>=C && B<=A)
{
medium = B;
small = C;
}
else
{
medium = C;
small = B;
}
} else if if(B>=A && B>=C)
{
//B is the largest, add code to determine medium and small as you did before
} else {
//C is the largest, add code to determine medium and small as you did before
}
}
添加回答
舉報(bào)