Last active
August 18, 2016 17:42
-
-
Save iporsut/41cd568f1c76e23b96bafb11ddd377ac to your computer and use it in GitHub Desktop.
Generate power print
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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