Java Program need help... Prompt: The elections are complicated on planet Galax.
ID: 3793662 • Letter: J
Question
Java Program need help...
Prompt: The elections are complicated on planet Galax. The winner isnt the person with the most votes, but the one whose vote total is divisible by both 3 and 8. The math always works out such that just one candidate satisfies both conditions, or else no one does, in which case a candidate is randomly chosen. Unfortunately the Galaxers dont know how to determine this. Once again, you come to the rescue with the following method:
public static String getWinner (int [ ] results, String [ ] names) { }
can you fill out the rest of the code?
Explanation / Answer
public static String getWinner (int [ ] results, String [ ] names)
{
int count = names.length();
String winner = "";
for(int i=0;i<count;i++)
{
if( results[i]% 3 == 0)
{
if( results[i]% 8 == 0)
{
winner = names[i];
return winner;
}
}
}
return "No one is winner";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.