Need to add to total columns to this array; one for rows and one for the columns
ID: 3640582 • Letter: N
Question
Need to add to total columns to this array; one for rows and one for the columns with labels:
just trying to use a (for) loop??
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; sRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.