write a java program to print the following series:
1 5 9 13 17...n terms
aryanburnwal8:
answer pls
Answers
Answered by
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
Answered by
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
Similar questions