Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4077930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:36:43+00:00 2026-05-20T17:36:43+00:00

This is my first attempt at java problem I have been given as part

  • 0

This is my first attempt at java problem I have been given as part of my Programming assignment.

I must make a program which calculates the average of a list of numbers that a user enters. the data enty should be terminated when 0 is entered. my problem is with this “ALL NEGATIVE NUMBERS SHOULD BE IGNORED”

for some reason the following code does not work, when I enter a negative number it should be ignored but for some reason it terminates the data enty

import java.util.*;

class Task_8
  {
public static void main()
  {

    Scanner inputLine = new Scanner(System.in);

    float row, numberentered, numbersum = 0, negativenumber = 0;
    double result, count = 0;


    System.out.println ("Welcome to Task 8 of 10 of my Programming Assignment... Nearly There!");
    System.out.println ("_____________________________________________________________________");
    System.out.println ();
    System.out.println ("Enter as many numbers as you like and this program will tell you the arithmatic mean");
    System.out.println ("Terminate data entry by entering 0");


   do{

       System.out.print ("Please enter a number: ");
        numberentered = inputLine.nextInt();

        count++;

        if (numberentered < 0)
        {
            numberentered  = negativenumber;   
        }

        numbersum = ( numberentered + numbersum ) - negativenumber;

    }

  while  ( numberentered !=0 );

     result = numbersum/count;
     System.out.println ();
     System.out.println ("*************************************");
     System.out.println ();
     System.out.println ("The sum of all of the numbers you entered is " +numbersum);
     System.out.println ("You entered " + count + " numbers");
     System.out.println ("The Average/mean of the numbers that you entered is " + result);


    System.out.println ();
    System.out.println ("*************************************");

  }
}

any Ideas guys?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:36:44+00:00Added an answer on May 20, 2026 at 5:36 pm

    The variable negativenumber always has the value zero. When you set numberentered to negativenumber the “while” condition is met, and the loop exits. A better strategy would be to us “continue” to skip the rest of the loop body when a negative number was entered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first attempt to create a GUI in MATLAB. I haven't been
Preface I've rarely ever been a JS developer and this is my first attempt
This is my first attempt to inline Java code in Perl. We cannot use
I have been trying to understand and solve this problem for the last three
This is my first attempt at responsive design, so I'm keeping it simple. I
This is my first attempt to write shorthand if statements however am befuddled by
this if my first attempt at using streaming for WCF, and I am struggling
this is my first attempt at a responsive design so excuse me if this
Because this is my first attempt at an extension method that seems quite useful
Up front: This is my first attempt at an Android app. I'm in that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.