Question: The task here is to complete the main method inside the class SumOfTriangles. The method should read ints from the user, compute their triangle (

The task here is to complete the main method inside the class SumOfTriangles. The method should read ints from the user, compute their "triangle" (see below) and add the "triangles" together until any negative number is entered. The method should then print out the sum of the triangles of all the non-negative integers entered (followed by a newline). If there are no non-negative integers before the first negative integer, the result should be 0.
The triangle of a positive integer nn is n(n+1)22n(n+1). Note that the numerator is always even, so you can safely do integer division.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!