Re: Java Help for a Beginner
- From: Booter <colo.avs96@xxxxxxxxx>
- Date: Thu, 22 Oct 2009 17:19:52 -0700 (PDT)
On Oct 22, 5:54 pm, Lew <no...@xxxxxxxxxxxxx> 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(System.in);
Scanner delimiter = new Scanner(System.in);
This is probably your problem. You've declared two scanners for System..in 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.
I was going through debug mode in Eclipse and noticed that when I got
to a negative number that my line:
grade = delimiter.nextInt();
was not preforming as expected. Does this method get negative