Number of Odd vs. Even Rows – Intro to Java Programming

If there are five rows: the first, third, and fifth would be odd rows, and the second and fourth would be even rows. But how would we generalize this, to figure this out let’s look at a couple more examples. If the total number of rows was 6, then even rows would be 3 and odd rows would also be 3. If the number of rows was 7, then odd rows would be 4 and even rows would still be 3. So, it looks like the number of odd rows is something like half of the total number of rows, but 4 isn’t exactly half of 7 over 2. It would be half of 7+1 over 2. What would happen if we added 1 on to this 6 as well. Then we will get 7 over 2, which in Javaland for integers is still 3. For the even rows 6 over 2 is 3, that one works. And 7 over 2 is pretty close to 3. In Javaland that’s 3. So, if I just divide by 2 and throw away the remainders, it looks like I get the numbers of even rows. If you don’t believe me, you can try a few more examples. So, it looks like the total number of odd rows is the total number of rows plus 1, over 2, and then drop the decimal. Whereas the number of even rows is just the total number of rows over 2, and we drop the decimal. There’s another way you could calculate the odd rows. You could say that the odd rows are always the total number of rows divided by two and then you add one if the total number of rows is odd. So, that would be the total number over 2 plus one if 7 is odd. And if 7 is odd then 7 mod two would be one. So, total mod 2. Save these for later. And you could also try this one.

Leave a Reply

Your email address will not be published. Required fields are marked *