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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:26:01+00:00 2026-05-25T00:26:01+00:00

/* * Application the reads an integer and prints sum of all even integers

  • 0
/*
 * Application the reads an integer and prints sum of all even integers between two and input    value
 */

import java.util.Scanner;

public class evenNumbers{

  public static void main(String [] args){
    int number;
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter an Integer greater than 1:");
    number = scan.nextInt();
    printNumber(number);
  }// end main


  /*declares an int variable called number and displays it on the screen*/
  public static void printNumber(int number){
    if (number < 2){
      System.out.println("Input value must not be less than 2");
    }
    int sum = 2;
     if(number % 2==0){
       sum+= number;
     }
     System.out.println("Sum of even numbers between 2 and " + number + " inclusive is: " + sum);

  }//end printnumber
}

I need to calculate the sum of 2 to the input number inclusive however, it only takes the last number and add two to it. COuld someone help me fix this.

  • 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-25T00:26:02+00:00Added an answer on May 25, 2026 at 12:26 am

    You need a loop. Your comment hints at the right direction, but you should look at the Java tutorials to see how to correctly write a ‘for’ loop. There are three parts: the initial declaration, the terminating condition and the loop step. Remember that the ++ operator only adds one to the variable. You can add other values using +=. If you use += to add a different value (like 2) to the loop variable, you can skip the ‘if’ test for even numbers. You can test for boundaries inclusively using the <= and >= comparison operators (for primitives). So you want something like this (in pseudocode, not Java):

     input the test value 
     Optional: reject invalid test value and **exit with message if it is not valid!** 
     initialize the sum variable to zero
     for ( intialize loop variable to 2; test that loop var <= test value; add 2 to loop var ) 
     { 
        add 'number' to the sum variable 
     } 
     display the sum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a console application written in c++. It simply reads an integer from
I am creating database Entities in my Java application and trying to rationalize between
Our C++ application reads configuration data from XML files that look something like this:
my ASP.NET application reads an xml file to determine which environment it's currently in
I have an application that reads a CSV file with piles of data rows.
I have an application that reads a database and outputs alerts to any dependencies
I have an application that reads a table from a database. I issue an
I have an application that reads lines from a file and runs its magic
I have an application that reads data from a com port using javax.comm. The
I'm writing an application which reads large arrays of floats and performs some simple

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.