Logo

Debug code

AI cracks the code! Paste, click, and watch errors vanish magically.

JDroid AI offers a one-click code debugging feature with an error explanation for 88 programming languages. Note:**** Thedebug code feature with an error explanation**** usesone AI credit. Our JDroid API also supports the feature for debugging code. For more information, refer to the JDroid API server documentation. Please refer to this documentation to learn the prerequisites for using JDroid AI.

Where can I find the ‘debug new code’ feature?

The ‘debug code’ feature is located within the JDroid box on the right side of the IDE. Debug code feature JDroid AI

Once your code compilation shows any errors, the ‘Debug with JDroid ’ button will also appear. You can select it, have your code debugged, and receive an error explanation as to why your code wasn’t executed. Debug with JDroid

Important notes:

  • When you opt for the optimize code feature, it will only **debug the code in the IDE. **

If you need to debug another code snippet, save the code in the IDE or discard it as you wish, paste the new snippet you wish to debug in the code editor, and select the debug code option. Refer to this documentation to understand how to save your code in the IDE.

  • The debug code detects code errors automatically upon execution only when syntax or logic errors are without output.

In that case, you must select the debug code feature from the right-hand side of the JDroid panel while ensuring the error code is still in the code editor.

How ‘debug code ’ works?

The working of JDroid AI’s debug code feature is straightforward. You just need to press debug code and get the corrected code and an error explanation when you feel your code has bugs. You can then paste the correct code into the IDE editor and execute it. We’ve used the Java Compiler IDE to show how debugging code with JDroid works. Debugging factorial code with JDroid

Here’s a sample of a factorial code with syntax and logic errors we will use. You can paste the code in the IDE and ask JDroid to debug it.

public class FactorialCalculator {
    public static void main(String[] args) {
        int number = 5; // We want to find the factorial of 5
        int factorial = factorial(number);
        System.out.println("Factorial of " + number + " is " + factorial);
    }

    // Incorrectly implemented factorial function
    public static int factorial(int n) {
        int result = ;  // Initialization error: Should be 1 because multiplying by 0 always results in 0
        for(int i = n; i > 0; i--) {
            resut *= i; // This will keep result as 0 due to initial value
        }
        return result;
    }
}

Here is the list of errors in this code snippet:

  • The missing semicolons after int number = 5, return result, and System.out.println(...) will throw errors.
  • The =* is not a valid operator in Java. The correct operator for multiplying and assigning is *=.

Example prompts to try

Here are sample code snippets with syntax and logic errors you can use to debug using JDroid. The samples provided are in JAVA, so you must use the JAVA IDE.

Sample Palindrome checker with errors

public class PalindromeChecker {
    public static void main(String[] args) {
        String input = "racecar";
        boolean isPalindrome = isPalindrome(input);
        System.out.println("Is '" + input + "' a palindrome? " + isPalindrome);
    }

    public static boolean isPalindrome(String text) {
        int left = 0;
        int right = text.length - 1; // Syntax error: incorrect method to get string length

        while(left < right) {
            if(text.charAt(left) != text.charAt[right) {
                left++; // Logic error: Should only increment `left` and decrement `right` if characters match
                right--;
            }
        }
        return True; // Logic error: Incorrect return, doesn't properly handle non-palindrome cases
    }
}

Here is the list of errors in the above sample:

  • Used text.length instead of text.length() to get string length.
  • No closing parenthesis after text.charAt(right) in the if condition.
  • The loop logic is wrong

Convert temperature to Fahrenheit or Celsius

public class SimpleInterestCalculator {
    public static void main(String[] args) {
        double principal = 10000;
        double rate = 5; // Logic error: Rate should be in percentage form or used as such in calculation
        int time = 3;

        double interest = calculateInterest(principal, rate, time);
        System.out.println("The simple interest is: " + interest)
    }

    public static double calculateInterest(double p, double r, int t) {
        return p * r * t / 100; // Syntax error: missing semicolon
    }
}

Here is the list of errors in the above sample:

  • Interest rate not adjusted for percentage in calculations.
  • Missing semicolon at the end of theSystem.out.println and calculateInterest return statements.

Things to consider while using debug code

JDroid AI is still learning and might be unable to debug the code, especially if:

  • The code you wish to debug is not pasted in the IDE
  • You’re using complex or new languages like Befunge,Cow,Brainfuck,Intercal, etc.
  • The code you ask it to debug is very complex.

Spotted a bug?

If you have a suggestion for a new feature (or a request), spotted a bug, or need more assistance, please fill out this form or email hello@jdoodle.com. Our support team will contact you as soon as possible. You can also ask your queries on our discord community.

Previous Topic ← AI credits & plans
Next Topic Explain code →