From: Booter on
On Oct 22, 6:27 pm, markspace <nos...(a)nowhere.com> wrote:
> Normally, I'd say "do your own homework."  It's important to ask your
> instructor or TA so they know where you are having trouble.  However,
> this may be a subtle error.
>
> Booter wrote:
> >            //set delimiter to a ","
> >            delimiter.useDelimiter(",");
>
> You might try ",\\s*" instead.  Normally there's white space in a file
> like this, and I'm not really sure what the response of the scanner will
> be if it tries to convert an int with white space.  Note that white
> space includes newlines, so I don't see how this will progress to a new
> line as you have it now.  If you have white space before the comma,
> you'll need something like "\\s*,\\s*".
>
> I could be all wrong, and I didn't test it, but it's something to look at..

So I tested it with the the following input:

1,2,3,-1

When it goes through the while loop it works until I get to the part
where

grade = delimiter.nextInt();

tries to get the -1. Once it reaches that line it just stalls and
doesn't progress any further.
From: Roedy Green on
On Thu, 22 Oct 2009 17:19:52 -0700 (PDT), Booter
<colo.avs96(a)gmail.com> wrote, quoted or indirectly quoted someone who
said :

> grade = delimiter.nextInt();
>
>was not preforming as expected. Does this method get negative
>numbers?

Javadoc says:

Scans the next token of the input as an int. This method will throw
InputMismatchException if the next token cannot be translated into a
valid int value as described below. If the translation is successful,
the scanner advances past the input that matched.

If the next token matches the Integer regular expression defined above
then the token is converted into an int value as if by removing all
locale specific prefixes, group separators, and locale specific
suffixes, then mapping non-ASCII digits into ASCII digits via
Character.digit, prepending a negative sign (-) if the locale specific
negative prefixes and suffixes were present, and passing the resulting
string to Integer.parseInt with the specified radix.

That means it wants simple ints, no spaces, no commas, but a single
lead - is ok.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
From: Booter on
On Oct 22, 7:13 pm, Roedy Green <see_webs...(a)mindprod.com.invalid>
wrote:
> On Thu, 22 Oct 2009 17:19:52 -0700 (PDT), Booter
> <colo.av...(a)gmail.com> wrote, quoted or indirectly quoted someone who
> said :
>
> >   grade = delimiter.nextInt();
>
> >was not preforming as expected.  Does this method get negative
> >numbers?
>
> Javadoc says:
>
> Scans the next token of the input as an int. This method will throw
> InputMismatchException if the next token cannot be translated into a
> valid int value as described below. If the translation is successful,
> the scanner advances past the input that matched.
>
> If the next token matches the Integer regular expression defined above
> then the token is converted into an int value as if by removing all
> locale specific prefixes, group separators, and locale specific
> suffixes, then mapping non-ASCII digits into ASCII digits via
> Character.digit, prepending a negative sign (-) if the locale specific
> negative prefixes and suffixes were present, and passing the resulting
> string to Integer.parseInt with the specified radix.
>
> That means it wants simple ints, no spaces, no commas, but a single
> lead - is ok.
> --
> Roedy Green Canadian Mind Productshttp://mindprod.com
>
> Nothing is so good as it seems beforehand.
> ~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)

Ok well that is all I have is a single - in front of the last number
but it just stalls once it reaches that point previously stated.

If it helps when the input is 1,2,3,-1,5 the loop will go through and
not get hung up on the -1 but will not do anything for the -1 or 5.
From: markspace on
Booter wrote:

> 1,2,3,-1

----------^

Here it is.

Delimiters in Scanner go on both sides of the token. So it's waiting
for a , after the -1 (or more digits), and stalls, waiting forever. I'd
add a newline to the delimiter, or maybe just whitespace.

Here's what fixed this problem for me:

//set delimiter to a "," or newline
delimiter.useDelimiter("(\\s*,\\s*)|\n");


This could probably use some improvement still.

>
> When it goes through the while loop it works until I get to the part
> where
>
> grade = delimiter.nextInt();
>
> tries to get the -1. Once it reaches that line it just stalls and
> doesn't progress any further.


'cause it's waiting for more input.

Really, you should have talked to your instructor or TA. This kind of
subtle use of regex is quite beyond a beginning student.

Please bring this to your instructor's immediate attention. They should
advise the beginner of the proper regex to use in cases like this.
From: Booter on
On Oct 22, 7:45 pm, markspace <nos...(a)nowhere.com> wrote:
> Booter wrote:
> > 1,2,3,-1
>
> ----------^
>
> Here it is.
>
> Delimiters in Scanner go on both sides of the token.  So it's waiting
> for a , after the -1 (or more digits), and stalls, waiting forever.  I'd
> add a newline to the delimiter, or maybe just whitespace.
>
> Here's what fixed this problem for me:
>
>    //set delimiter to a "," or newline
>    delimiter.useDelimiter("(\\s*,\\s*)|\n");
>
> This could probably use some improvement still.
>
>
>
> > When it goes through the while loop it works until I get to the part
> > where
>
> > grade = delimiter.nextInt();
>
> > tries to get the -1.  Once it reaches that line it just stalls and
> > doesn't progress any further.
>
> 'cause it's waiting for more input.
>
> Really, you should have talked to your instructor or TA.  This kind of
> subtle use of regex is quite beyond a beginning student.
>
> Please bring this to your instructor's immediate attention.  They should
> advise the beginner of the proper regex to use in cases like this.

Thank you every one for all of your help. I could not have gotten
this done without you.