Homework 2

Out: Tue 27 Jan 1998
Due: During Lab Session

Programming Assignment:

Write, compile and run the TriangleNumbers.java program to calculate and print the triangle numbers. Begin with a copy of the program Boom.java and modify it. Add a variable int sum, initially zero, but incremented according to the variable i, which in this case, will be increasing from 0 to count. The triangle numbers are 1, 3, 6, 10, 15, etc., where the pattern is clear when the numbers are drawn as triangles:

                                  x
                         x        xx
                 x       xx       xxx
          x      xx      xxx      xxxx
  x       xx     xxx     xxxx     xxxxx

  1       1+2=3  3+3=6   6+4=10   10+5=15

Your lab instructor will be responsible for checking and grading your work.