write a program to print the following series 0,25,122 in java
Answers
Answered by
4
Question:-
➡ Write a Java program to print the following series.
0 25 122....N terms.
Program:-
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n, i, c=1, x;
System.out.print("Enter the value of n: ");
n=sc.nextInt();
for(i=1;i<=n;i++,c+=2)
{
x=(c*c*c)-i;
System.out.print(x+" ");
}
System.out.println("Program Finished.");
}
}
Logic:-
➡ 0 = 1³ - 1
➡ 25 = 3³ - 2
➡ 122 = 5³ - 3
and so on,...
Answered by
2
Answer:
1³-1
2³-2
3³-3
.
.
.
(n^n)-n
import java. util. *;
class Series
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in) ;
System. out. println("Enter no. of terms") ;
int n=sc.nextInt() ;
int i, c=1, k;
for(i=1;i<=n;i++)
{
k=Math.pow(k, 3)-i;
System.out.print(k+", ") ;
}
}
}
Similar questions
History,
2 months ago
English,
2 months ago
Biology,
2 months ago
Computer Science,
5 months ago
Social Sciences,
5 months ago
Math,
11 months ago