Respuesta :

Here goes my best explanation:


Ok

So i'm assuming you know the basics of Java

I can't say i'm familiar with it. I'm currently learning c++

So by the end of this, t will be 20


Why?


Each time the first for loop iterates, the second for loop iterates too right?

p=0 q=0 t=1  //This is the first iteration. p and q are both 0, and 1 is added to t. The second for loop starts.

p=0 q=1 t=2  //This continues until q is 4. p WILL NOT iterate again until q is done with it's iterations.

p=0 q=2 t=3

p=0 q=3 t=4  //q is 4, thus ending the loop.

p=1 q=0 t=5  //p iterates once more. p is now 1, and the second loop starts again. Why? Because for each iteration of p, q iterates until it is finished.

p=1 q=1 t=6

p=1 q=2 t=7

p=1 q=3 t=8

p=2 q=0 t=9

p=2 q=1 t=10

p=2 q=2 t=11

p=2 q=3 t=12

p=3 q=0 t=13

p=3 q=1 t=14

p=3 q=2 t=15

p=3 q=3 t=16

p=4 q=0 t=17

p=4 q=1 t=18

p=4 q=2 t=19

p=4 q=3 t=20


This output was taken from me running the code itself. The comments were added by me afterwords.


ACCESS MORE