+ 2

Please help me solve this code(Java)coach. I am not confused this doesn't seem to work

I was trying to solve a code coach in this code I had to find the percentage of 2house out of no of total no of house but it doesn't work Let me explain I had to find%of 2houses out of 3 which is 66.66 something but I am getting 66 only and I also added the remainder then I got 68 I am so confused please help me 😨😕 Take a look at my code https://code.sololearn.com/c0bPSN55hZiF/?ref=app

2nd Apr 2020, 12:32 PM
Atoms~⚛
Atoms~⚛ - avatar
1 Resposta
0
The problem here is that you are working with ints. You need to get a double percentage and then round it up. In other words: if you divide two ints, you get the lower nearest integer. Imagine you divide 10/3, you get 3. So, in order to get an exact division, you need to work with doubles. You can do that by making one of the operands a double. In the example above: double result = 10/3.0 (see how I've included a decimal in the denominator). In this case, result is 3.33... Now, you would need to round that up to the higher nearest integer, which you can do using Math.ceil(result). Try it out!
2nd Apr 2020, 12:58 PM
Mario M G
Mario M G - avatar