Thank you very much. I'm so appreciated your help.
On Aug 27, 11:50 am, Jos Snellings <[email protected]>
wrote:
> Hi,
>
> The problem is that the ".toString()" method won't work as you expected.
> The proper way to build a string with your acquired input is:
>
> String fromCmdLine = new String(buffer).
> That makes sure your typed in ints will be coming in correctly.
>
> Best,
> Jos
>
>
>
> On Thu, Aug 27, 2009 at 5:21 AM, CJ<[email protected]> wrote:
>
> > I'm a college student. So this problem may be a little silly. Thanks
> > to help me.
> > Why it always throw the NumberFormatException?
> > ---------------------------------------------------------------------------------------------------------------------
> > ArrayList<Integer> inputNum = new ArrayList<Integer>();
>
> > try {
> > System.out.println(" Please input an integer:");
> > while (true) {
> > byte buffer[] = new byte[128];
> > System.in.read(buffer);
> > if ("end".equals(buffer.toString().trim())) {
> > break;
> > }
> > else {
> > inputNum.add(Integer.parseInt(buffer.toString().trim()));
> > }
> > }
> > }
> > catch (IOException e) {
> > System.out.println(e.toString());
> > }
> > catch (NumberFormatException e) {
> > System.out.println("Please input an integer.");
> > }
> > ---------------------------------------------------------------------------------------------------------------------
> > Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---