tag:blogger.com,1999:blog-5872623838295077986.post3038692576693955084..comments2024-03-20T01:07:56.465-07:00Comments on JavaProblems.com - Free coding problems and exercises: Java > Recursion-1 > triangle (CodingBat Solution)Unknownnoreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5872623838295077986.post-34237033030469023272022-01-18T23:30:43.588-08:002022-01-18T23:30:43.588-08:00 return rows==0?0:rows+triangle(rows-1);
return rows==0?0:rows+triangle(rows-1);<br />Flash_Investor_INhttps://www.blogger.com/profile/11077535428909343630noreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-73363825605287421592019-01-08T15:10:14.352-08:002019-01-08T15:10:14.352-08:00same result
public int triangle(int rows) {
if(...same result<br /><br />public int triangle(int rows) {<br /> if(rows == 0) {<br /> return 0;<br /> }<br /> <br /> return rows + triangle(rows - 1);<br />}fergcodyhttps://www.blogger.com/profile/11057253259169571379noreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-89322438878695595322018-05-04T01:29:13.802-07:002018-05-04T01:29:13.802-07:00public int triangle(int rows) {
return (rows ==...public int triangle(int rows) {<br /> return (rows ==0)? 0 : triangle(rows-1)+rows;<br />}Anonymoushttps://www.blogger.com/profile/15442693482222280045noreply@blogger.comtag:blogger.com,1999:blog-5872623838295077986.post-84183267347037998482016-11-11T22:58:41.238-08:002016-11-11T22:58:41.238-08:00this is also the summation from i = 0 to i = n of ...this is also the summation from i = 0 to i = n of i, so an alternative solution to the problem is simply n*(n+1)/2Anonymousnoreply@blogger.com