How to print 1,2,4,7,11...n using java
// always focus on the first number and mark the difference pattern
// common way to write
int a=1,n=10 ; // n value you can take anything
for(int i=1;i<=n;i++)
{
System.out.println(a);
a=a+i;
}
// always focus on the first number and mark the difference pattern
// common way to write
int a=1,n=10 ; // n value you can take anything
for(int i=1;i<=n;i++)
{
System.out.println(a);
a=a+i;
}
Comments
Post a Comment