爲什麼這個代碼總是返回0總是返回零
public int loveCal(String bname, String gname) {
char[] boy_name = bname.toLowerCase().toCharArray();
char[] girl_name = gname.toLowerCase().toCharArray();
int boy = 0;
int girl = 0;
int love = 0;
for(int i = 0; i < bname.length(); i++)
boy += (int) boy_name[i];
for(int i = 0; i < gname.length(); i++)
girl += (int) girl_name[i];
if(boy > girl)
love = (girl/boy)*100;
else
love = (boy/girl)*100;
return love;
}
+1」用零乘以100不會有幫助。「 – f1sh