+ 3
How to do?
I want a program in java to generate the following series up to 10 terms. 0,3,8,15,24,35,....
5 Answers
+ 12
jothika Bennett Post
//have a look at direct way đ
âby seeing the series , it is clear that odd numbers are added after each iteration
â odd number 2*n+1 , ie 3,5,7,9 & so on for n=1,2,3 resp.
//so lets use it
int a=0,n=1;
for(;n<10;n++){
System.out.println(a);
a+=2*n+1;
}
+ 3
public class Program
{
public static void main(String[] args) {
int b,a;
for(b=3;b<=21;b=b+2)
for(a=0;a=a+b)
{
System.out.println(a);
}
}
}
is this how i have to do Bennett Post
+ 3
thanks Bennett Post
+ 3
thanks Pavel Zubakha
+ 2
There are squere numbers wich reduced by 1
Also you can find it using loop:
https://code.sololearn.com/cbW6A1u0o8A4/?ref=app
public class Program
{
public static void main(String[] args) {
for(int n = 1; n <= 10; n++)
System.out.println(n * n - 1);
}
}