Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok I'm trying to figure out this problem using a t-chart

C++
for (int i = 1; i < 5; i++)
      for(int k = i; k > 2; k--)
        System.out.print(k + "");


My t-chart

i   K
1   -
2   -
3   2
4   3
5   4


output

2 3 4

suppose to be

3 4 3 how???

What I have tried:

The problem works great in JGrasp I just need more clarification on the output
Posted
Updated 24-Feb-17 8:50am
v2
Comments
Bryian Tan 24-Feb-17 14:23pm    
3 4 3 sound correct.

Um.
I just tried it. 343 is what I get.

Assuming you copied and pasted that code, I'd check that it compiles correctly in situ - i.e. that the other code around it isn't causing compiler errors, preventing a new executable file being created. If it is, then you are running an older version of the software than you expect, which would explain the difference.
 
Share this answer
 
Quote:
My t-chart

Your chart is wrong, use the debugger, it will show you how variables evolve step by step. Give it a try, you will see it is very instructive.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900