I have a double array that has the population of some cities in the first array, and the populations of the country those cities are in in the 2nd array.
double[][] population = new double[][]{
{24153000,18590000,18000000,14657000,14543000,13617000,13197596,12877000,12784000,12400000,12038000,
11908000,11548000,11035000,10608000,10355000,10290000,10152000,10125000,9752000},
{1384688986,1384688986,207862518,81257239,162951560,126168156,143964513,105920222,
1384688986,1296834042,207652865,1384688986,1384688986,1296834042,1384688986,207862518,50791919,1384688986,86300000,31773839
}
I am trying to find the percent of a Countries population that lives in the city. So I have a for loop that divides array 1 at some index by the equivalent index at array 2. The body of the loop says
double percent= (population[0][i]*100f)/population[1][i];
Yet I keep getting integer division. For example, for dividing the first elements of both arrays, I get 2 instead of 1.744.
Can anyone tell me why this is happening? I am getting whole numbers only even though I am dividing doubles and not ints.
Edit: Here is the rest of the loop. There is some extra stuff, such as i'm only supposed to print out the cities that have over 10m people. Also some formatting.
for (int i = 0; i < population[1].length; i++) {
if (population[0][i] > 10000000) {
double percent = (population[0][i]*100f)/population[1][i];
System.out.printf("%10.0f", percent);
System.out.println();
}