Question: this is java. Please help me understand how to code this Create a class, called TriangleNumbers, that has a static public method called genNum that
this is java. Please help me understand how to code this
Create a class, called TriangleNumbers, that has a static public method called genNum that takes one non-negative integer argument n, and returns the nth triangle number, an integer. The nth triangle number is defined as the sum of numbers 1 through n, inclusive. For example: First triangle number = 1 Third triangle number = 1 + 2 + 3 = 6 Ninth triangle number =1+2 + 3 + ... + 8 + 9 = 45 The program should prompt the user to enter an integer x (you can safely assume it is greater than 0), and then print the first x triangle numbers, with each j^th line holding the j^th triangle number amount of values, separated by commas (except for the last number in every line). So the first line would contain the first triangle number, the second line would contain the next three, the third line would contain the next six, the fourth line would contain the next ten, and so forth. Sample input/output: User enters 4, program outputs: 1 3, 6, 10 User enters 22, program outputs: 1 3, 6, 10 15, 21, 28, 36, 45, 55 66, 78, 91, 105, 120, 136, 153, 171, 190, 210 231, 253
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
