Computer Science, asked by aryanburnwal8, 4 months ago

write a java program to print the following series:
1 5 9 13 17...n terms​


aryanburnwal8: answer pls

Answers

Answered by itsmepapakigudiya
4

Answer:

Given series is 1,5,9,13,17,...

Common difference (d)=5−1=4

First term is a=1

So n

th

term is t

n

=a+(n−1)d=1+(n−1)4=4n−3

∴t

n

=4n−3


aryanburnwal8: please write the program it will be very helpful
Answered by DüllStâr
68

Required program:

import java.util.*;

public class series

{

public static void main()

{

Scanner sc = new Scanner (System.in);

int n;

System.out. print("Entered number is");

n =sc.nextInt();

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

{

System. out.print(i+",");

}

}

}

Or:

public class series

{

public static void main(int n)

{

System. out.println("Entered number is"+n);

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

System. out.println(i+",");

}

}

Input:

n=26

Output

1,5,9,13,17,21,25


DüllStâr: sorry that program is pretty difficult ^^"
aryanburnwal8: oh ok
aryanburnwal8: i was wondering
anindyaadhikari13: It should print n terms of the series.
DüllStâr: In both programs?
anindyaadhikari13: Yes. For example, if the n is 10,then it should print 10 terms of the series.
DüllStâr: but yah I have written this only see the for loop , I have given extent upto n terms only ^^"
anindyaadhikari13: No, you have taken n=26 but first 26 terms are not displayed.
anindyaadhikari13: Only 7 terms are displayed.
DüllStâr: oh right I will correct it asap
Similar questions