go to previous page   go to home page   go to next page hear noise highlighting

Answer:

Yes.


Formula for Triangle

Triangle is so easy that you don't need to use either iteration or recursion for it. You might recognize Triangle(N) as the sum the first N integers:

1 + 2 + 3 + ... + (N-1) + N  = (N * (N+1))/2

For example

1 + 2 + 3 + 4  = (4*5) / 2 = 10

Of course, implementing this formula in Java is simple. And that is how you would do it in a practical situation. But the goal of this chapter was to show recursion with Java and triangle numbers work well for that.


QUESTION 22:

Are you ready for another example?


go to previous page   go to home page   go to next page