Hola Brainlians!
Let's have some evening challenges!!
Create your own Java Program to print the following series.
2 10 30 68 130 222...nth term
Difficulty Level: Medium.
_
Thanks,do not spam
Answers
Answered by
6
Solution:
This is the required códe for the question.
import java.util.*;
public class Series {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter limit - ");
int n,i,a;
n=sc.nextInt();
for(i=1;i<=n;i++){
a=i+(i * i * i);
System.out.print(a+" ");
}
}
}
Logic:
- nth term = n + n³
See output in the picture.
Attachments:
Similar questions