-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICG.java
25 lines (22 loc) · 889 Bytes
/
ICG.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;
public class CodeGenerationForIf {
public static void main(String[] args) {
// Example input: if (x > 5) { y = x * 2; }
String condition = "x > 5";
String action = "y = x * 2;";
// Generate code for the if statement
String generatedCode = generateIfCode(condition, action);
System.out.println("Generated code:");
System.out.println(generatedCode);
}
public static String generateIfCode(String condition, String action) {
StringBuilder codeBuilder = new StringBuilder();
// Add the if statement
codeBuilder.append("if (").append(condition).append(") {\n");
// Add the action inside the if block
codeBuilder.append("\t").append(action).append("\n");
// Close the if block
codeBuilder.append("}");
return codeBuilder.toString();
}
}