Solved

# Sum numbers 1 through 10

Posted on 2006-10-25
214 Views
I can't quite get the running total correct. I am supposed to sum the numbers 1 through ten and print the result.
My numbers are off.

public class Sum
{
public static void main(String args[])
{
int total = 2;

for(int i = 1; i <= 10; i++)
{
total += i;
System.out.printf("i = %d\n",i);
System.out.printf("total= %d\n", total);
}

}
}

Any help would be greatly appreciated.
0
Question by:deekakes

LVL 37

Accepted Solution

momi_sabag earned 500 total points
ID: 17805045
hi

i believe the error is in
int total = 2;
it should be
int total = 0;

momi sabag
0

Author Comment

ID: 17805084
Thank you so much...I fell asleep on that one!!!!!!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…