How to debugging in Netbeans Java

How to debugging in Netbeans Java

Step 0: Write a Java Program

The following program computes and prints the factorial of n (=1*2*3*...*n). The program, however, has a logical error and produce a wrong answer for n=20 (“The Factorial of 20 is -2102132736” – a negative number?!)

/** Compute the factorial of n */
public class Factorial {
// Print factorial of n
public static void main(String[] args) {
int n = 20;
int factorial = 1;

// n! = 1*2*3...*n
for (int i = 1; i <= n; i++) {
factorial *= i;
}
System.out.println("The Factorial of " + n + " is " + factorial);
}
}

Step 1: Set an initial Breakpoint

A breakpoint suspends program execution for you to examine the internal states of the program. Before starting the debugger, you need to set at least one breakpoint to suspend the execution inside the program. Set a breakpoint at main() method by clicking on the left-margin of the line containing main(). A red circle or an inverted Triangle appears in the left-margin indicating a breakpoint is set at that line.

How to set Breakpoint in Netbeans

debug running in Netbeans

panel for debug

Variable appear from