NEW QUESTION!!
Q) WAP in JAVA to print the following series:-
64, 125, 216, 343, 512, 1024, 3125, 7776, 16807, 32768....Nth term
__________
•Answerers requested to attach their output of the program(if possible).
•Please do not post irrelevant answers/comments
___
Thank you :)
#BeBrainly
Answers
Required Answer:-
Question:
Write a Java program to print the following series.
64 125 216 343 512 1024 3125 7776 16897 32768...N terms.
Solution:
Here comes the program.
import java.util.*;
public class Series {
public static void main(String[] args) {
int n, a=4, b=3;
Scanner sc=new Scanner(System.in);
System.out.print("Enter limit - ");
n=sc.nextInt();
for(int i=1;i<=n;i++) {
System.out.print((int)Math.pow(a, b)+" ");
a++;
if(a>8) {
a=4;
b+=2;
}
}
sc.close();
}
}
Explanation:
Logic for the program is as follows -
4³, 5³, ... 8³, 4⁵, 5⁵,...8⁵ and so on.
We will create two variables a and b
Initially,
a = 4, b = 2
After each iteration, value of a^b is displayed on the screen and values of a is incremented by 1. Next term becomes 5^b, 6^b and so on.
When a becomes greater than 8, b is incremented by 2 and a becomes 4 again. In this way, the program works.
Check out the attachment. ☑
Answer:
Required Answer:- Question: Write a Java program to print the following series. 64 125 216 343 512 1024 3125 7776 16897 32768...N terms. Solution: Here comes the program. import java.util.*; public class Series { public static void main(String[] args) { int n, a=4, b=3; Scanner sc=new Scanner(System.in); System.out.print("Enter limit - "); n=sc.nextInt(); for(int i=1;i<=n;i++) { System.out.print((int)Math.pow(a, b)+" "); a++; if(a>8) { a=4; b+=2; } } sc.close(); } } Explanation: Logic for the program is as follows - 4³, 5³, ... 8³, 4⁵, 5⁵,...8⁵ and so on. We will create two variables a and b Initially, a = 4, b = 2 After each iteration, value of a^b is displayed on the screen and values of a is incremented by 1. Next term becomes 5^b, 6^b and so on. When a becomes greater than 8, b is incremented by 2 and a becomes 4 again. In this way, the program works. Check out the attachment. ☑
Explanation: