Sorry for the vague title it's 3:30 in the morning and I really want to get this done.

My problem is that I am adding together two integers and dividing by two to find the average of them.
Because the numbers are between 0 and 255 I will sometimes end up with a '.5' on the end which of course my compiler doesn't like.
Is there a method for removing such occurrences? If not, how would I got about getting around this problem.

Quick note, no I can't just declare a double instead as I am passed an array of Int's to work with.

You'll never get doubles as a result of int/int division. So (a + b) / 2 will always be an integer.

May 26th, 2013, 12:33 PM

Blinktwink

Re: Removing fractions from Integers

Oh really? Thank you for that informative tidbit, must be another error in my code some where.

--- Update ---

Turns out I'm getting an "Array out of bounds exception" with this line.

Code Java:

int b = other[rows][cols];

Still got no clue why though.

May 26th, 2013, 01:08 PM

angstrem

Re: Removing fractions from Integers

Of course you get. Look at the meaning of rows and cols variables. Also, remind me, why might you need i and ii variables in the loops?

May 27th, 2013, 01:54 AM

Blinktwink

Re: Removing fractions from Integers

i stands for index. ii is simply my second index for my nested loop. It's the incrementation of these which controls the loop. I understand that there is a syntax 'for each' that I haven't quite mastered yet as I have only just started learning programming.

The rows variable is the minimum number of rows out of the two arrays and the same for cols. This is to ensure that I don't try to assign a number to the this.image array that may be out of bounds.

May 27th, 2013, 02:03 AM

pbrockway2

Re: Removing fractions from Integers

It's your program, so forgive me for saying that I and ii don't stand for "index": they stand for "row" and "column". Or, to use angstrem's word, they mean row and column. Which raises the question... Why, when you use for loops to set row and column to various values, don't you actually use those values inside the loops?

May 27th, 2013, 02:16 AM

Blinktwink

Re: Removing fractions from Integers

Oh wow I can't believe I didn't see what I was doing wrong. Feel like a right idiot now. It was so obvious yet somehow it eluded me, it always seems to be that way though. Thanks for the help this makes so much more sense now.