Hi, Andrei,

As I suspected, readLine() retains the newline character, and
parseInt() doesn't like it.  You need to strip that newline
away.
        Igor

Andrei Blackness <k7...@yahoo.com> wrote on 12/02/2009 11:17:30 AM:

> Thank you for your response Igor. I didnt realize it trunked my 
> message. I will repost the code. I added it the x10 file as an 
attachment too. 
> 
> public class Hello {
>     public static def main(args:Rail[String]!){
>          if(args.length>0){
>            Console.OUT.println("The first arg is: "+args(0));
>          }
>          Console.OUT.println("Enter a number: ");
>          val h = new Hello();  // final variable 
>          h.myMethod(); 
>     }
>     /** x10doc comment for myMethod */;
>     public def myMethod(){
>     try{
>         val limit:String = Console.IN.readLine();
>         Console.OUT.println("The read number is: "+limit);
>         Console.OUT.println("The sum of the first "+limit+" numbers is: 
");
>         var s:int=0;
>         val n:int = Int.parseInt(limit);
>         for(var i:int=0;i<n;i++){
>         s=s+i;
>         }
>         Console.OUT.println(s);
>     }
>     catch(e:IOException){}
>     }
> }
> 
> The version of the language is 2.0. 
> 
> The error message is
> 
> The read number is: 10
> 
> The sum of the first 10
>  numbers is: 
> java.lang.NumberFormatException: For input string: "10
> "
> at java.lang.NumberFormatException.forInputString(Unknown Source)
> at java.lang.Integer.parseInt(Unknown Source)
> at java.lang.Integer.parseInt(Unknown Source)
> at Hello.myMethod(Hello.java:130)
> at Hello.main(Hello.java:93)
> at Hello$Main$2.apply(Hello.java:52)
> at x10.runtime.Runtime$4.apply(Runtime.java:310)
> at x10.runtime.Activity.run(Activity.java:127)
> at x10.runtime.Runtime$25.apply(Runtime.java:1599)
> at x10.runtime.impl.java.Runtime.runAt(Runtime.java:101)
> at x10.runtime.Runtime.run(Runtime.java:1566)
> at x10.runtime.Worker.loop(Worker.java:302)
> at x10.runtime.Worker.apply(Worker.java:193)
> at x10.runtime.Pool.apply(Pool.java:207)
> at x10.runtime.Runtime.start(Runtime.java:317)
> at Hello$Main.main(Hello.java:35)
> at x10.runtime.impl.java.Runtime.run(Runtime.java:46)
> at java.lang.Thread.run(Unknown Source)
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to