I'm trying to divide two numbers to get a percentage, then print it. Here's the relevant method:
public void process_winner(String candidates[], int votes[])
{
double percent = (mostVotes / votes.length) * 100;
if (mostVotes > votes.length / 2)
System.out.println("Winner: " + candidates[mostVotesIndex] + "(" + percent + "%)");
else
System.out.println("None (no majority)");
System.out.println("");
}
the problem line is:
double percent = mostVotes / votes.length;
mostVotes
is an int
, with a value of 6, and votes.length
is 10. I verified this using the debugger.
It's showing a value of 0.0 for my percent variable, when it should show 60.0