Solved

Sum numbers 1 through 10

Posted on 2006-10-25
2
217 Views
Last Modified: 2010-03-31
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
Comment
Question by:deekakes
2 Comments
 
LVL 37

Accepted Solution

by:
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

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question