Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Very beginner level code help needed.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Thanked 0 Times in 0 Posts

    Question Very beginner level code help needed.

    This code should display "incorrect entry" if a entry is not <=100 or =999. I think my code is in the wrong area but can't figure it our where it goes.

    import java.util.Scanner;
    public class ModifiedTestScoreApp
        public static void main(String[] args)
            // display operational messages
            System.out.println("Please enter test scores that range from 0 to 100.");
            System.out.println("To end the program enter 999.");
            System.out.println();  // print a blank line
            // initialize variables and create a Scanner object
            double scoreTotal = 0;
            int scoreCount = 0;
            int testScore = 0;
            Scanner sc = new Scanner(System.in);
            // get a series of test scores from the user
            while (testScore <= 100)
                // get the input from the user
                System.out.print("Enter score: ");
                testScore = sc.nextInt();
                // accumulate score count and score total
                if (testScore <= 100)
                    scoreCount = scoreCount + 1;
                    scoreTotal = scoreTotal + testScore;
                else if (testScore != 999)
                     System.out.println("Invalid entry, not counted");
            // display the score count, score total, and average score
            double averageScore = scoreTotal / scoreCount;
            String message = "\n"
                    + "Score count:   " + scoreCount + "\n"
                    + "Score total:   " + scoreTotal + "\n"
                    + "Average score: " + averageScore + "\n";

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,705 Times in 2,655 Posts

    Default Re: Very beginner level code help needed.

    What does the code do now when it is compiled and executed?
    Show the program's input and output and add some comments saying what the output should be.

    Suggestion: Print out the value of testScore at the end of the error message so you can see what the bad value is.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java file processing beginner level
    By candoa in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 20th, 2012, 09:54 PM
  2. Creating a Simple, Beginner-Level Vowel Counter
    By tryingtolearn in forum Collections and Generics
    Replies: 1
    Last Post: July 8th, 2012, 03:25 PM
  3. Replies: 1
    Last Post: April 18th, 2012, 01:12 PM
  4. Help needed for beginner. Im so confused
    By walrus212 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 14th, 2011, 01:47 PM
  5. Quick, beginner-level Java question.
    By DHG in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2011, 01:06 PM