Jussi said:
Patricia said:
You are thinking about the wrong question when you talk about "only even
numbers" and arbitrary functions with even values.
int t = first value;
for (int j = 0 ; j < a.length ; ++ j) {
for (int k = 0 ; k < a[j].length ; ++ k) {
a[j][k] = t;
t = next value;
}
}
Sirius, what Jussi describes here is the simplest solution, not the most
fancy, comprehensive or solution. I think there is a lesson here for
you, which is one of the most important lessons you will ever learn when
programming. Keeping it as simple as possible will save you a lot of
headache with unmanageable code or a lot of time chasing ugly bugs.
The major point to take home with you here is that even though a
solution might seem simple enough, you have to assess the cost of using
a slightly, or much, more complicated solution, throughout the
application. Your original problem is just a simple problem, but you ran
in to a problem which was hard to solve. And if you have enough of them
in a complete system it all adds up in maintenance/complexity cost for
the project, meaning that you might end up spending f.ex 30% of your
coding/maintenance time chasing bugs or maintaining code that you could
have spent on developing new features or programs.
Programming is 50% about creating maintainable code, and this you do by
selecting the simplest solutions for the problem (which you can later
extend), choosing the correct/simplest design and documenting your code
well enough (I.e. document code by writing simple code with short and
concise method descriptions, and by adding code comments only for those
statements where the functionality is not obvious.)
I hope this advice helps you.
tom