Вы находитесь на странице: 1из 1

/**

* Write a description of class SquareTriangular here.


*
* @author (your name)
* @version (a version number or a date)
*/
public class SquareTriangular
{
/**
* An example of a method - replace this comment with your own
*
* @param y
a sample parameter for a method
* @return
the sum of x and y
*/
public void printthetriangularnumbers(int n)
{
int count=0;
int sum=0;
for (int j=1;j<=Integer.MAX_VALUE;j++)
{
sum= (int) ((j*(j+1))/2);
if (sum==1)
{
count++;
System.out.println(sum);
if(count==n)
break;
}
else
{
for (int test=1; test<=sum/2; test++)
{if(test*test==sum)
{
count++;
System.out.println(sum);
break;
}
}
}
if(count==n)
{break;}
}
}
}

Вам также может понравиться