Generate new code
JDoodle AI offers a feature togenerate new code, which turns plain text input or prompts into** working code. It currently supports over 110+ languages, the same as our IDE. _Note:**_ Thegenerate new code feature** usesone AI credit.**
Where can I find the ‘generate new code’ feature?
Here are a few ways you can access JDoodle AI’s generate new code feature.
- When you click ‘Let’s code ’ on the homepage or search for your preferred language in the header’s search bar, you’ll be directed to create a new JDrive (projects).
You can start coding with a sample code generated from JDoodle AI by entering it into the prompt box. 
- You’ll find a floating JDoodle AI symbol in the IDE editor to your right. When you click the JDoodle AI symbol, the chat opens, and you can talk to JDoodle AI and get the code you need using a simple prompt.

Important note:
JDoodle AI will generate prompts in the same language as your chosen IDE. For example, if you are in the JAVA compiler IDE, you cannot ask JDoodle AI to generate code in C++ or any other language except JAVA. If you ask the same in the prompt, you will still get code in the same language as the IDE. If you wish to generate code in a different language, go to the IDE where you want the generated code. For example, if you want a code snippet in C++, you must go to the C++ compiler IDE.
How ‘generate new code ’ works?
The working of the generate new code feature is straightforward. You must specify the details you need in your code in the prompt you’re giving to JDoodle AI and hit enter. We’ve used the Java Compiler IDE and gave a prompt to generate astring reversal code. 
Here’s the output given by JDoodle AI:
public class Main {
public static void main(String[] args) {
String str = "Hello World";
String reversed = reverseString(str);
System.out.println("Reversed String is: " + reversed);
}
public static String reverseString(String str) {
String reversed = "";
for(int i = str.length() - 1; i >= 0; i--) {
reversed = reversed + str.charAt(i);
}
return reversed;
}
}
Rules for writing prompts
- The capabilities of JDoodle AI are extensive. You can ask JDoodle AI to add several snippets in a single prompt to the code you want.
For example, you can ask JDoodle AI to generate a code that creates a Fibonacci series, create an array on the series, perform sorting on it, then search for the position of a specific number, and so on.
- If you wish to get input from the user, it’s better to specify it beforehand in the prompt to get precisely what you need. The more specific prompt you can provide, the better output you can get.
For example, in the above string reversal code provided by JDoodle AI, you can specify you want the input string from the user. In this case, you can then use the STDIN box to provide input or turn on the ‘interactive mode.’
- Ensure your class is “public ” so your code can be executed in the IDE.
If you still encounter errors while executing, you can select the debugging feature of JDoodle AI. To learn more about JDoodle AI’s debug code feature, read this documentation.
Example prompts to try
Here are some sample prompts to try. You can choose any language you wish for these prompts. As an example, we will show output in the JAVA IDE.
Implement a calculator with basic arithmetic operations.
Here’s the output provided by JDoodle AI:
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter two numbers: ");
double num1 = scanner.nextDouble();
double num2 = scanner.nextDouble();
System.out.println("Enter an operator (+, -, *, /): ");
char operator = scanner.next().charAt(0);
scanner.close();
double output;
switch (operator) {
case '+':
output = num1 + num2;
break;
case '-':
output = num1 - num2;
break;
case '*':
output = num1 * num2;
break;
case '/':
if (num2 != 0) {
output = num1 / num2;
} else {
System.out.println("Cannot divide by zero");
return;
}
break;
// operator doesn't match any case constant (+, -, *, /)
default:
System.out.println("Error: Invalid operator");
return;
}
System.out.println(num1 + " " + operator + " " + num2 + " = " + output);
}
}
Convert temperature to Fahrenheit or Celsius
Here’s the output provided by JDoodle AI:
import java.util.Scanner;
public class TemperatureConverter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter temperature:");
double temperature = scanner.nextDouble();
System.out.println("Enter unit (F for Fahrenheit, C for Celsius):");
char unit = scanner.next().charAt(0);
double convertedTemperature;
if (unit == 'F' || unit == 'f') {
convertedTemperature = (temperature - 32) * 5 / 9;
System.out.println("Temperature in Celsius: " + convertedTemperature);
} else if (unit == 'C' || unit == 'c') {
convertedTemperature = (temperature * 9 / 5) + 32;
System.out.println("Temperature in Fahrenheit: " + convertedTemperature);
} else {
System.out.println("Invalid unit. Please enter F for Fahrenheit or C for Celsius.");
}
scanner.close();
}
}
Things to consider while writing prompts
Here are a few cases where JDoodle AI can produce the wrong code or produce no output.
- You might get a wrong answer if you request that JDoodle AI generate code in a different language from your selected IDE.
- JDoodle AI may not give the right answer if you’re using complex or new languages like Befunge,Cow,Brainfuck,Intercal, etc.
- JDoodle AI is still learning! It can generate an error in the code if you ask it to perform something very complex.
- JDoodle AI is only created for coding-related tasks. The below categories of prompt will not work correctly:
- Meaning of words like ‘flabbergasted’
- Mention that you need input from the user
- Ask for locations or prompts like ‘Give me a chocolate.’
Found 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.
