Write a program in Java to print the following series: 1,4,7,10,13,16.............n
Answers
Answered by
2
Question:-
Write a program in Java to print the following series.
1 4 7 10 13 16....N terms.
Program:-
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value of N: ");
int n=sc.nextInt(),a=1;
for(int i=1;i<=n;i++,a+=3)
System.out.print(a+" ");
}
}
Similar questions