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 7549687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:00:37+00:00 2026-05-30T10:00:37+00:00

I have an assignment to find the minimum, maximum, and average of numbers that

  • 0

I have an assignment to find the minimum, maximum, and average of numbers that a user inputs. Basically, they type in positive integers, seperated by a space and Java scrolls through them and adds them up. I’m able to find the sum, the average, and the largest integers, however, I am unable to find the smallest. I thought the best way to figure this out would be to set the variable representing the smallest int equal to the variable representing the largest int outside of the loop. Then, within the loop, do something like this:

        if(getInt < min)
        {
            min = getInt;
        }

Where getInt is the user-inputted value and min is the minimum integer value. Every time I run this, though, min returns as 0.

Here is my full code:

import java.util.Scanner;

public class exc5
{
    public static void main (String[] args)
    {  
        System.out.println("Write a list of nonnegative integers, each seperated by a space. To signal the end of the list, write a negative integer. The negative integer will not be counted");
        Scanner keyboard = new Scanner (System.in);
        keyboard.useDelimiter(" |\n");

        int count = 0;
        int sum = 0;
        int max = 0;
        int min = max;
        double average = 0;

        boolean notNull = true;

        while(notNull == true)
        {
            int getInt = keyboard.nextInt();

            if(getInt < 0)
            {
                notNull = false;
            }  
            else
            {          
                if(getInt > max)
                {
                    max = getInt;
                }

                if(getInt < min)
                {
                    min = getInt;
                }

                sum += getInt;
                count++;
                average = (sum)/(count);
            }
        }

        System.out.println("Sum = " + sum);
        System.out.println("Average = " + average);
        System.out.println("Max = " + max);
        System.out.println("Minimum = " + min);
    }

}

Any help is appreciated!

  • 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-30T10:00:38+00:00Added an answer on May 30, 2026 at 10:00 am

    This:

            int max = 0;
            int min = max;
    

    initializes min to zero. (After all, max hasn’t become the largest integer yet.) So this:

                    if(getInt < min)
    

    will never be true. Try changing this:

            int min = max;
    

    to this:

            int min = Integer.MAX_VALUE; // largest possible Java `int`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have an assignment that requires me to find the mode of a
I have this homework assignment where the user is asked to input numbers and
I got an assignment that I find it quite challenging and I have no
I have an assignment that is the following: For a given integer array, find
My boss have given me assignment to find how a web based application developed
I have an assignment that wants me to write an ternary search algorithm and
I have an assignment that simulates a dice game. As part of the program,
I have an assignment to read a file and output the average test scores.
Okay I have an assignment to find the Kth smallest element in the list
I have an assignment at school to build a webserver that handles GET/HEAD/PUT requests,

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.