Dania Khan wrote:I'm trying to teach myself Java and came across a problem I'm hoping to get insight on. I need to basically figure out what the possible output is for candidate blocks of code, which would be substituted in the program where the underline is. Here it is:
Tip: I suspect it's because you're trying to take it all in at once. DON'T. Take each line you don't understand
one at a time.
Get lots of paper, and a pencil and work through it. For example:
for (int outer = 0; outer < 3; outer ++) { ...
What does it do? What are the possible values for '
outer'? Forget about everything else and concentrate on THAT.
Then try the next loop, and do the same - and don't forget that the inner loop will be executed
completely for
each iteration of the outer one.
Then, I'd advise making some tables and tracing through each iteration in turn, noting down the value of each variable as you go.
Very often, after a few rounds, something will leap out at you and you'll go "ah, so THAT'S what it's doing"; but you won't get there unless you put in the hard work.
Welcome to programming.
Winston