Sum numbers 1 through 10

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.
deekakesAsked:
Who is Participating?
 
momi_sabagConnect With a Mentor Commented:
hi

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


momi sabag
0
 
deekakesAuthor Commented:
Thank you so much...I fell asleep on that one!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.