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

  • Home
  • SEARCH
  • 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 8664055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:08:52+00:00 2026-06-12T17:08:52+00:00

The assignment instructions are so: Write a method named evenSum that prompts the user

  • 0

The assignment instructions are so: Write a method named evenSum that prompts the user for many integers and print the total even sum and maximum of the even numbers. You may assume that the user types at least one non-negative even integer. I have everything written correctly except for one last part.

That part is determining the number with the highest value that is also an even number. So, I have it in the body of an if statement (numbers % 2 == 0). How do I figure out the maximum number? By the way, I can’t use arrays and I’ve tried Math.max but I’m not sure how to use it to determine the max.

public void evenSum()
{
int sumamount = 0;
int evenMax = 0;
int numberOfInputs = 0;
int numbers = 0;
Scanner in = new Scanner(System.in);


System.out.print("how many integers? ");
numberOfInputs = in.nextInt();


for(int i = 0; i < numberOfInputs; i++)
    {
        System.out.print("next integer? ");
        numbers = in.nextInt();

        if(numbers % 2 == 0)
            {
                sumamount += numbers;
                if(numbers > numbers)
                {
                    evenMax = numbers
                }
            }
            else
                numbers = 0;


    }


        System.out.print("even sum = ");
        System.out.println(sumamount);
        System.out.print("even max = ");
        System.out.println(evenMax);
    }
  • 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-06-12T17:08:54+00:00Added an answer on June 12, 2026 at 5:08 pm

    This line is the culprit:

    if(numbers > numbers)
    {
        evenMax = numbers
    }
    

    The condition should be

    if (evenMax < numbers) {
        evenMax = numbers;
    }
    

    Also, it may be better to initialize evenMax to -1 (an odd number) and handle the case where it is -1 and initialize with the first input appropriately (i.e first even input). This will handle the cases where all the inputs are negative even numbers.

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

Sidebar

Related Questions

My assignment is to write an overloaded version of iquote() , a method that
Current assignment needs me to write a program to read a file with instructions
My assignment instructions are rolling 2 dice and getting the sum and then finding
Assignment: Write a C++ program to read the menu information from menu.txt. First letter
My assignment is to create a simple graph that has both Nodes and Edges.
My assignment requires that I have an ER diagram that shows the dependencies between
I have an assignment that I'm supposed to implement the MIPS processor in C++
For my CS11 class, I have to write a small applet that draws a
I have an assignment where we need to write a (very simplified) multithreaded compression
Im trying to write a simple scheme function that returns the last element of

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.