Skip to content

Instantly share code, notes, and snippets.

@iporsut
Last active August 18, 2016 17:42
Show Gist options
  • Save iporsut/41cd568f1c76e23b96bafb11ddd377ac to your computer and use it in GitHub Desktop.
Save iporsut/41cd568f1c76e23b96bafb11ddd377ac to your computer and use it in GitHub Desktop.
Generate power print
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Replicate {
public static void main(String []args) throws IOException, InterruptedException {
int n = 3;
List<String> ls = new ArrayList<String>();
ls.add("public class Gen {");
ls.add("\tpublic static void main(String []args) {");
for (int i = 0; i < n; i++) {
ls.add("for(int i"+i+" = 0; i"+i+" < "+n+"; i"+i+"++) {");
}
ls.add("System.out.print('A');");
for (int i = 0; i < n; i++) {
ls.add("}");
}
ls.add("\t}");
ls.add("}");
Files.write(Paths.get("Gen.java"), ls);
Process child = Runtime.getRuntime().exec("javac Gen.java");
child.waitFor();
child = Runtime.getRuntime().exec("java Gen");
BufferedReader in = new BufferedReader(new InputStreamReader(child.getInputStream()));
int c = -1;
while ((c = in.read()) != -1) {
System.out.print((char)c);
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment