Question: Why this code always return 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;
}

```

Answer: 
Your divisions will always return 0 since the dividend is usually smaller than the divisor. It could in rare cases be equal!

Do the multiplication before the division:

```
if( boy > girl )
    love = (girl * 100) / boy;
else
    love = (boy * 100) / girl;

```
If:

```
boy > girl

```

then:

```
girl/boy

```

always returns `0` because of integer division rounding. Try this:

```
100.0f * girl / boy

```

Which is equivalent but casts `girl` to `float` first and avoiding integer rounding.