// CSE 142, Summer 2008, Helene Martin // Uses a three-element array to store vote counts for three candidates. import java.util.*; public class TallyVotes { public static void main(String[] args) { // string stores votes: (M)cCain, (O)bama, (I)ndep. String votes = "MOOOOOOMMMMMOOOOOOMOMMIMOMMIMOMMIIIIIIIIIIIIII"; int[] tallies = tallyVotes(votes); System.out.println(Arrays.toString(tallies)); } public static int[] tallyVotes(String votes) { int[] tally = new int[3]; for(int i = 0; i < votes.length(); i++) { if(votes.charAt(i) == 'M') { tally[0]++; } else if(votes.charAt(i) == 'O') { tally[1]++; } else { // charAt(i0 == 'I' tally[2]++; } } return tally; } }