Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 09 Apr 2013 02:28:12 -0500 Date: Tue, 09 Apr 2013 08:28:11 +0100 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Inserting Multiple Lines from Console References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 47 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-LhqFFgZ3lZREbvv6V4JOa0zk/zUD5SrtNYGc4X3oJrr4nQA2s712jNlbtkUoq8z/OLUX+gknMt3U3kr!FHwnSjs2cfs3jhP42ywSoAJNsHB0K2qgaeZLSRbmz/WFexuBC8Iv4SVdnbgEd7QKGxptBtVoMnY= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3346 Xref: csiph.com comp.lang.java.programmer:23396 On 08/04/13 15:06, Stefan Ram wrote: > subhabangalore@gmail.com writes: >> If anyone can kindly suggest how may I improve it? > > public class Main > { > public void quit(){ java.lang.System.exit( 0 ); } > > public void main() throws java.lang.Throwable > { final javax.script.ScriptEngine scriptEngine > = new javax.script.ScriptEngineManager().getEngineByName( "JavaScript" ); > scriptEngine.put( "main", this ); > final java.lang.StringBuilder text = new java.lang.StringBuilder(); > scriptEngine.put( "text", text ); > scriptEngine.eval( "print('');" ); // loads engine for faster reaction > java.lang.System.out.printf > ( "*** Texteditor 2000, V1.0 ***%n%n %d Bytes Free%n%n Enter%n%ntext." + > "append('example');%n%n or other StringBuilder calls in JavaScript " + > "syntax to edit,%n%n or enter%n%nmain.quit();%n%n to quit.%n%n", > java.lang.Runtime.getRuntime().freeMemory() ); > while( true )try > { java.lang.System.out.printf( "%n> ", text ); > java.lang.System.out.println > ( scriptEngine.eval( System.console().readLine() )); > java.lang.System.out.printf( "%s%n", text ); } > catch( final java.lang.Throwable throwable ) > { java.lang.System.err.println( throwable ); }} > > public static void main( final java.lang.String[] args ) > throws java.lang.Throwable { new Main().main(); }} This is surreal, if you run this code, the output is ... well interesting to say the least. Not sure how it meets the OP requirements but in fairness I'm not sure what the OP requirements are in the fist place so who's to say it's not 'correct' Incidentally if you strip all the unnecessary garbage from the code and introduce some sanity to the formating it does make it slightly easier to read. Very strange, is it mushroom season where you are? lipska -- Lipska the KatŠ: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun