Please Help me to understand
Can someone explain this code please
I cant understand what will print out...
Please note that i dont want to run it on a program, i would like to understand it.
for (int x=13; x<20; x+=3){
int z=x-8;
for (int y=x; y>z; y-=2)
System.out.print(y+" ");
System.out.println(x);
}
Thanks
Re: Please Help me to understand
One help for you to see what the code does is for the code to be properly formatted.
Also you should always use {}s with for loops and if statements to clearly show what statements are part of the loops and if statements.
Also Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
First thing to do would be to compile and execute the code and see what it prints out.
Execute the code, copy the output and pasted it here so we can see what the code does.
It's a waste of time talking about what some code could do, when you can execute it and see what it really does.
For more info, add a println that prints out the value of z after it is given a value.
Re: Please Help me to understand
With these unlikely pieces of code, the intention is to teach you to hand-trace.
Make a table with all the variables and then run through the program manually.