UnPatoCuacCuac
UnPatoCuacCuac

Reputation: 345

Sum Two Dimensional Arrays

I'm suppose to add the sum of the votes per state and the sum per candidate of this two dimensional array.

These are the requirements:

Upvotes: 0

Views: 1213

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499750

The problem has nothing to do with summation, and everything to do with formatting. Just this code will demonstrate the same problem:

int[] values = new int[10];
new Formatter().format("%21d", values);

It's not clear what you expected this to do, but I suspect you actually want to either do something like:

// Please change your variable names to follow Java conventions
fmt = new Formatter(System.out);
for (int value : Totalbystate) {
    fmt.format("%21d", value);
}

Alternatively, specify a single format string such as "%21d%21d%21d%21d%21d" (etc) and pass in an Integer[] instead of an int[].

Additionally, you should fix your program's indentation - it's unnecessarily confusing at the moment.

Upvotes: 6

Related Questions