Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to add to total columns to this array; one for rows and one for the columns

ID: 3640614 • Letter: N

Question

Need to add to total columns to this array; one for rows and one for the columns with labels:
I'm trying to use a (for) loop to give me the totals??
Please Help!
public static void main(String[] args) throws IOException
{
File election = new File("voting_2008.txt");
Scanner sc = new Scanner(election);

String[] states = new String[51];
int[][] votes = new int[51][3];

for(int s=0; s < 51; s ++)
{
states[s] = sc.nextLine();
}

for (int c=0; c < 3; c++)
{
for(int s=0; s < 51; s++)
{
votes[s][c] = sc.nextInt();
}
}
Formatter fmt = new Formatter();
fmt.format("%20s%12s%12s%12s", "State", "Obama", "McCain", "Other");
System.out.println(fmt);
for(int s=0; s < 51; s ++)
{
fmt = new Formatter();
fmt.format("%20s", states[s]);
System.out.print(fmt);
for(int c=0; c < 3; c++)
{
fmt = new Formatter();
fmt.format("%12d", votes[s][c]);
System.out.print(fmt);
}
System.out.println();
}
}

Explanation / Answer

File election = new File ("voting_2008.txt"); Scanner sc = new Scanner(election); String[] states = new String[51]; int[][] votes = new int[51][3]; int sum; for(int s=0; s
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote