Created
July 28, 2012 15:57
-
-
Save dtinth/3193829 to your computer and use it in GitHub Desktop.
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
print("Enter your name: ") | |
puts("Hello, " + gets()) |
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.io.BufferedReader; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import org.mozilla.javascript.*; | |
public class Main { | |
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
public static void main(String[] args) throws FileNotFoundException, IOException { | |
Context cx = Context.enter(); | |
try { | |
ScriptableObject scope = cx.initStandardObjects(); | |
String[] functions = { "gets", "puts", "print" }; | |
scope.defineFunctionProperties(functions, Main.class, ScriptableObject.DONTENUM); | |
cx.evaluateReader(scope, new FileReader(args[0]), args[0], 1, null); | |
} finally { | |
Context.exit(); | |
} | |
} | |
public static String gets() throws IOException { | |
String line = reader.readLine(); | |
if (line.endsWith("\r\n")) { | |
line = line.substring(0, line.length() - 2); | |
} else if (line.endsWith("\n")) { | |
line = line.substring(0, line.length() - 1); | |
} | |
return line; | |
} | |
public static void puts(String x) { | |
System.out.println(x); | |
} | |
public static void print(String x) { | |
System.out.print(x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment