Write the program in Java to display the first ten terms of the following series:
a) 1,4,9,16,...
b) 1,2,4,7,11,...
c) 3,6,9,12,...
Answers
Answer:
a) int num=1, add=3, inc=2;
for (count=0, count<10, count++) {
s.o.p(num);
num = num + add;
add = add + inc;
}
b) int num=1, count=0, add=1, inc=1;
for (count=0, count<10, count++) {
s.o.p(num);
num = num + add;
add = add + inc;
}
c) int num=3, count=0, add=3;
for (count=0, count<10, count++) {
s.o.p(num);
num = num + add;
count = count+1;
}
Explanation:
Note :- There can be various methods of writing the same program.
s.o.p stands for System.out.println
num = starting digit
add = number that is to be added to num at each iteration
inc = number by which add has to increased each time.
like in part 'a', 3 has to be added first, then 5, then 7 and so on.
So Inc is 2. which means that every time 2 more has to be added.
Answer:
1,4,9,16,25,36,49,64,81,100
Explanation:
public class series
{
int k;
public void display()
{
int t=0;
for(k=1;k<=17;k+=2)
t=t+k;
System.out.print(t+" , ");
{
System.out.print("100");
}
}
}