Can I use debugger in Java code before printing to the console and understand values?

The IntelliJ IDEA program has a debugging option, but I don't know if I can check the intermediate values of the variables through it. For example, in the code, when I put a breakpoint, I don't know how I could add the input values to see the intermediate values.

Upvotes: 0

Views: 96

Answers (2)

Andrey
Andrey

Reputation: 16381

If you mean to set the variable values through the debugger, - yes, you can use Set from the context menu of the variable:

Set variable values If there is a need to test how the program would behave in certain conditions or fix its current behavior at runtime, you can do that by setting/changing the variable values.

  1. Right-click a variable on the Variables tab and select Set value, or select the variable and press F2.

  2. Enter the value for the variable and press ⏎.

Enter new value for the variable in the field right next to its name

Upvotes: 1

queeg
queeg

Reputation: 9384

Of course you can debug your code and step through it to better understand what is happening. In essence, you would set a breakpoint at a location of your interest, then tell IntelliJ to run your program in debug mode (breakpoints enabled). How to do this exactly can be seen from various fine resources:

Upvotes: 2

Related Questions