Search

Google
 

Wednesday, January 23, 2008

JAVA ICSE BLUEJ program

Series question

WAP to print the series:-S = 1+(1+2)+(1+2+3)+ --------+(1+2+3--------+n)

//SUPPLY N AS PARAMETER URSELF
class series2
{
void main(int n)
{
int S=0;
for (int c=1;c<=n;c++)
{for (int d=1;d<=c;d++)
{
S=S+d;
}
}
System.out.println(S);
}
}

No comments: