Other Online IDE: Online Java Debugger - online editor (onlinegdb.com)
The following code doesn’t get the expected result.
You need to use the debug technique to find why it doesn’t working correctly.
Draw a heart shape.
The heart shape equation is:
(x^2+y^2-1)^3-x^2*y^3=0
Use the following code and use the debug technique to find where need to fix:
class Main {
public static void main(String[] args) {
for (double y = 1.5; y > -1.5; y -= 0.1) {
for (double x = -1.5; x < 1.5; x += 0.05) {
double temp = (x * x) + (y * y) - 1;
double value = (temp * temp * temp) - (x * x) * (y * y * y);
if (value == 0.0)// Fix me
System.out.print(" ");
else
System.out.print("❤");
}
System.out.println();
}
}
}
Answer:
class Main { public static void main(String[] args) { for (double y = 1.5; y > -1.5; y -= 0.1) { for (double x = -1.5; x < 1.5; x += 0.05) { double temp = (x * x) + (y * y) - 1; double value = (temp * temp * temp) - (x * x) * (y * y * y); if (value >= 0.0) System.out.print(" "); else System.out.print("❤"); } System.out.println(); } } }
Find the debugger button on the left side Tools
Create a breakpoint
, click the left side of the line column.
Click the Run
button.
Run
button.On replit, you should run the programm first. Then, use the debugger.
Because replit use the command
Debug (sh -c java-debug)
to debug the running command.
[Desmos | Graphing Calculator](https://www.desmos.com/calculator) |