Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
JavaScript on Java's System.out.println()
import java.io.*; import javax.script.*; class Rextester { public static void main(String[] args) { System.out.println("var i;" + "for(i=1; i<=100; i++){" + "print((i%3==0?'Fizz':'')+(i%5==0?'Buzz':'')||i);" + "}"); } static { System.setOut(new Kicker(System.out)); } static class Kicker extends PrintStream { PrintStream out; ScriptEngine engine; public Kicker(PrintStream out) { super((OutputStream) new ByteArrayOutputStream()); this.out = out; ScriptEngineManager manager = new ScriptEngineManager(); engine = manager.getEngineByName("js"); ScriptContext context = engine.getContext(); Writer writer = new OutputStreamWriter(out); context.setWriter(writer); } @Override public void println(String str) { try { engine.eval(str); } catch (ScriptException e) { throw new RuntimeException(e); } } } }
run
|
edit
|
history
|
help
2
preincrement
jb12.0 threads.enums
Ridhiverma
Dynamic Array
Scope
Alphabets
Wenfeng Ou
Java
++a vs a++ and calculations around different variables
2c