Re: Java Help for a Beginner

Booter wrote:
I am working on a program that can takes numbers in as grades with a
delimiter of a ",". I have most of the code working but for some
reason I can never get out of the while loop in the code. If anyone
can help it would be greatly appreciated.


import java.util.*;// need scanner

public class Grades
public static void main (String[] args)

Do not embed TAB characters in Usenet posts. Use spaces, a maximum of four per indent level.

People have to be able to read your code to help you with it.

Scanner classGrades = new Scanner(;
Scanner delimiter = new Scanner(;

This is probably your problem. You've declared two scanners for and you don't seem ever to use the first one. Why do you need two? Why don't you use the first one?

System.out.print("Welcome to the Grade Calculator Program \n\n"
+ "Please enter the student scores as integers between 0 and

Those darn TAB characters!

+ "Separate the scores with a comma.\n"
+ "Follow the last student score with a negative number.\n"
+ "Enter the grades here: ");

//declairations [sic] for vars needed
int grade = 0;
int a = 0;

It is better in languages like Java to name a variable with a whole word that indicates its meaning in the logic of the problem. Readers have to ask, "What is an 'a'?" A better name would be "aCount" or "countOfA" or "numberOfAs".

int b = 0;

I took a guess, but for this kind of question you should also report (copied-and-pasted) what your test inputs and resulting outputs were.


Relevant Pages

  • Re: Scanner annoyances
    ... have to set the delimiter each time before I call "nextBigDecimal". ... I had trouble with Scanner and found StreamTokenizer more familiar. ... see now that Scanner recognizes a rich variety of tokens, ...
  • Re: java.util.Scanner and EOF/EOT issues
    ... You didn't enter a number <- no user interaction ... "delimiter" based approach used by the Scanner class since even after ... then the Scanner *should* work remarkably like BufferedReader's readLine; ... file and the file contains an empty line every block of ten data ...
  • Re: Scanner Bug?
    ... Scanner uses a Matcher, obtained from the supplied Pattern, to look for delimiters. ... But the Matcher knows nothing about the Readable being used. ... So, as far as it's concerned, the end of the input is the end of the CharBuffer. ... _Maybe_ there's some logic they could include that would see whether any actual tokens had been eliminated from the input, and refuse to return a token until either the true end-of-input has been reached, or some actual delimiter text has been consumed. ...
  • Re: Exporting a table into Access2003.
    ... With a scanner I have successfully ... paragraph marks you'll ... This reply is posted in the Newsgroup; ...