I was actually looking for a quick way to evaluate nested loops by hand. Such as when you have to take the SCJP exam and have only your paper and pencil in hand.
I thought I read somewhere using a matrix with usign the row and columns and placing a check, line, or X through possible choices.
When I was doing SCJP mock tests, etc. when my brain had turned to jam I would write out the variable names as column headings. It's particularly useful for those loop examples that contain a switch with lots of ++, -- and missing breaks.
I guess the matrix might be appropriate for absolute beginners but I would have thought it would be too time-consuming to bother for SCJP. Also relies on known break conditions.
Originally posted by Julian Kennedy: When I was doing SCJP mock tests, etc. when my brain had turned to jam I would write out the variable names as column headings. It's particularly useful for those loop examples that contain a switch with lots of ++, -- and missing breaks.
I guess the matrix might be appropriate for absolute beginners but I would have thought it would be too time-consuming to bother for SCJP. Also relies on known break conditions.
Jules
I do the same. The variable names are the column headings and each row represents a loop iteration.
James, If you are looking for a good workbook to use along with any Java fundamentals textbook, then my book would be a good choice. Please click on the link in my signature.
The book is printed and distributed by booksurgepublishing.com. That's why the booksurge web page has a little more information than the Amazon page. The book cover image and other information should be on the Amazon page within the next couple weeks.
I will look at it. Every semester I teach Java I give my students a list of Java Reference books and Websites. I include certification books. If it has tip and trick it I would definitely recommend it.
Since it not published with a major company, I can't get a free exam copy can I?
I think that the most useful feature of my book is the detailed explanations of the answers. The chapters of the book are organized such as those of the Study Guide 1 exam set on my web site. Each of those chapters begins with an introduction to the material covered by the mock exam in that chapter. Since the book is intended to serve as a workbook to accompany any Java fundamentals textbook, the chapter introductions are not intended to replace any Java fundamentals textbook. My book also contains some helpful appendicies.
My book contains 398 pages with very narrow margins and text printed in a small font. The dimensions of my book are 8.25 inches by 10.5 inches. Most Java textbooks today are printed on smaller pages with very wide margins and large fonts. If I had used a more typical page size and margin widths, the book might have contained twice as many pages. In other words, there is a lot of content packed into those 398 pages.
Since my book is self published, the cost of any sample copies comes out of my pocket. I can give you a sample chapter at no charge. Just click on that link.
It might be interesting to "unwind" the loops and set up a problem and solution without loops. For example, number all the squares on a 3x3 checkerboard:
Hmmm, I guess start with a 1 dimensional problem first, solve it the long way then with a loop. Then seeing the 2 dim problem newbies ought to be able to spot the first dimension holding steady while a very similar loop goes through the second dimension.
Originally posted by James Chegwidden: >[QB]Hello, All
>Another semester is upon us. I will teach Java Programming at my college again >this semester (as well as C and C++)
>I am looking for tips and tricks to show my students how to evaluate nested >loops like
As a student at the beginner level in Computer Science, I'm trying to work out the same problem as you. My professor uses a column system where rows indicate iterations. However, I never understood what was going on until I understood how the loop structure worked itself. To do this I wrote a short program in C, simple enough that I could see how loops worked- simple because the relationships between the outputs and the inputs were clear and could not confuse.
#include <stdio.h>
int main() { int a, b, c;
for (a = 1; a <5 ; a++) for (b=2; b<5 ; b++) for (c=3; c<5 ; c++) printf("%d %d %d\n", a,b,c);
return 0; }
From comparing this and the output, I was able to figure it out...about 10 minutes ago!
-jake
Post by:autobot
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, that will fit in a stocking