How to print 1,2,3,4...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++;

}


// Short cut way to write

int n=10 ;  // n value you can take anything

for(int i=1;i<=n;i++)

{

System.out.println(i);

a++;

}

Comments

Popular posts from this blog