Solved

Sum numbers 1 through 10

Posted on 2006-10-25
2
213 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now