- 1
How to generate series 4,32,128,256,...n in java
14 Respuestas
+ 2
Martin Taylor maybe after 256 comes 128 because
256*(1/2)=128
then
128*(1/4)=32
32 * 1/8 = 4
4 * 1/16 =1/4
1/4*1/16=1/64
so on...
+ 2
If the multiplicator is divided by 2 in each step and is stored as float, the series is 4, 32, 128, 256, 256, 128, 32, 4, 1/4, 1/128, 1/8192, ...
It quickly approaches 0 but never reaches it, i.e. limes is 0.
Recursive definition is a bit tricky, because it needs two variables:
x_i = x_i-1 * y_i-1
y_i = y_i-1 / 2
Alternative:
x_i = x_i-1 * 2 ^ z_i-1
z_i = z_i-1 - 1
Base case:
x_0 = 4, y_0 = 8, z_0 = 3
+ 1
Martin Taylor I think there is mupltiplier is decreasing by half.
4 * 8= 32
32 *(8/2) = 128
128*((8/2)/2) = 256
so on, so forth))
+ 1
Martin,
Same doubt here, I was waiting for the OP's response ...
+ 1
Ashish Katta
Is this a right solution?
https://code.sololearn.com/cMLKjgqxtlg4/?ref=app
0
Thank you
0
But not working for these series
0
All the numbers are powers of 2
Is there an input taken for that series?
What numbers go beyond 256?
0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int num = 4,j=8;
System.out.print(num + " ");
for (int i = 1; i < n; i++) {
num=num*j;
System.out.print(num + " ");
j=j/2;
}
}
}
- 1
import java.util.*;
class series
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of terms");
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
int j=i+1;
System.out.print(i*j*j+",");
}
}
}
- 1
Somthing like this bro
int a= 4;
for(int i=4;i<=n; i=i/2)
{
System.out.print(a + "," );
a=a*i;
}
🙃
Wish if that helps u bro