So I've been giving a number of assignments to do but I'm stuck on one in particular now. I've to create a 2D array ([5][2]) and then say how many times ou of the 5 rows that the first row was bigger than the second. I imagined I would need a counter and that it would go something like below but depending on where I print the result it comes out as either 2 or 7....when of course, it isn't 2 or 7 :P I have the array decalred in the main method and all that, just this part I'm stuck on. Thanks for any help.

static void Won(int s[][])
		int counter = 0;

		for(int r=0; r<s.length; r++)
			counter = 0;

			for(int c=0; c<s[0].length; c++)

Recommended Answers

All 2 Replies

why do you need a counter?
unless I'm mistaken about what you're trying to do, you just need to compare the size of the arrays, not the contents.
In which case, you're just fine with checking the .length of the two you need to compare

Do you mean the value inside the first row at its corresponding column is bigger than other rows?

If so, you just need to iterate through row=1 to s.length. The reason is that you already know and will access your first row (row=0) every time you check. Also, when you check for the value, you need to access it as s[r][c] instead of using r or c. The r and c in this case are indexes for the passing array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.