Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #23396

Re: Inserting Multiple Lines from Console

Date 2013-04-09 08:28 +0100
From lipska the kat <"nospam at neversurrender dot co dot uk">
Organization Trollbusters 3
Newsgroups comp.lang.java.programmer
Subject Re: Inserting Multiple Lines from Console
References <e88303ce-910f-4aad-af1a-895ce3ca4a8b@googlegroups.com> <Texteditor-20130408160509@ram.dialup.fu-berlin.de>
Message-ID <tIudncopGZSRXv7MnZ2dnUVZ8h6dnZ2d@bt.com> (permalink)

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Inserting Multiple Lines from Console subhabangalore@gmail.com - 2013-04-08 06:59 -0700
  Re: Inserting Multiple Lines from Console Joerg Meier <joergmmeier@arcor.de> - 2013-04-08 17:04 +0200
    Re: Inserting Multiple Lines from Console Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-04-08 14:10 -0700
      Re: Inserting Multiple Lines from Console Lew <lewbloch@gmail.com> - 2013-04-08 15:10 -0700
        Re: Inserting Multiple Lines from Console x@x.com (znôrt) - 2013-04-09 01:08 +0200
          Re: Inserting Multiple Lines from Console Lew <lewbloch@gmail.com> - 2013-04-08 17:59 -0700
            Re: Inserting Multiple Lines from Console x@x.com (znôrt) - 2013-04-09 08:46 +0200
            Re: Inserting Multiple Lines from Console Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-04-09 05:39 -0300
              Re: Inserting Multiple Lines from Console Martin Gregorie <martin@address-in-sig.invalid> - 2013-04-09 23:04 +0000
              Re: Inserting Multiple Lines from Console x@x.com (znôrt) - 2013-04-10 19:45 +0200
                Re: Inserting Multiple Lines from Console Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-10 14:43 -0400
                Re: Inserting Multiple Lines from Console Gene Wirchenko <genew@telus.net> - 2013-04-11 11:11 -0700
                Re: Inserting Multiple Lines from Console Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-04-11 15:05 -0400
  Re: Inserting Multiple Lines from Console lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-08 16:21 +0100
  Re: Inserting Multiple Lines from Console markspace <markspace@nospam.nospam> - 2013-04-08 09:56 -0700
  Re: Inserting Multiple Lines from Console lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-04-09 08:28 +0100

csiph-web