TWiki . Doc . StrcatBeginnerExample

/* Please try the NoviceExamples before the BeginnerExamples
To compile:
   nicec --sourcepath=.. -a strcat.jar strcat
To run:
   java -jar strcat.jar 40000
*/


void main(String[] args){
   var n = toSingleInt(args);
   let s = "hello\n";
   let buffer = new StringBuffer(32);

   while (n-- > 0) buffer.append(s);

   println(buffer.length); 
}


int toSingleInt(String[] s){
   try { return Integer.parseInt(s[0]); }
   catch (Exception e){ return 1; } }


/* Notes - language
Compare with Java at the "Win32 Language Shootout"

   let buffer = new StringBuffer(32);
Declare and initialize StringBuffer buffer, the compiler will infer 
the type from the initial assignment. Identifiers declared with 
keyword let can be assigned a value only once. 

*/
-- IsaacGouy - 27 Aug 2003

----- Revision r1.4 - 10 Jan 2004 - 19:06 GMT - IsaacGouy
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.