[Solved] How to debug logical errors in IntelliJ


One aspect of the issue is the intermingling of presentation with calculation. As a result, it is difficult to debug the result, as well as to write test cases for it.

Rather than :

System.out.println("The total number of minutes is " + 60 * hour + minute);

It would likely be preferable to have a method:

public int calculateMinutes(int hours, int minutes)
{
   //perform calculations
}

Then one could write a series of test cases with known values against the method, and have a reasonable expectation that the result is correct. Then, one
can do something similar to (using the hours, minutes in the OP’s question):

int totalMinutes = calculateMinutes(hour, minute);
System.out.println("The total number of minutes is " + totalMinutes);

In this way, there is a hope of debugging, by both writing test cases and potentially stepping through the method.

TL;DR: separate calculations from presentation to support test cases and debugging.

solved How to debug logical errors in IntelliJ