- 1

How to generate series 4,32,128,256,...n in java

26th Mar 2021, 12:58 PM
Ashish Katta
Ashish Katta - avatar
11 ответов
+ 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...
26th Mar 2021, 7:08 PM
Sharofiddin
Sharofiddin - avatar
+ 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
26th Mar 2021, 10:10 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 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))
26th Mar 2021, 4:00 PM
Sharofiddin
Sharofiddin - avatar
+ 1
Martin, Same doubt here, I was waiting for the OP's response ...
26th Mar 2021, 4:20 PM
Ipang
26th Mar 2021, 4:35 PM
A͢J
A͢J - avatar
0
Thank you
26th Mar 2021, 1:02 PM
Ashish Katta
Ashish Katta - avatar
0
But not working for these series
26th Mar 2021, 1:07 PM
Ashish Katta
Ashish Katta - avatar
0
All the numbers are powers of 2 Is there an input taken for that series? What numbers go beyond 256?
26th Mar 2021, 2:43 PM
Ipang
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; } } }
26th Feb 2023, 1:04 PM
sachin kamley
sachin kamley - avatar
- 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+","); } } }
26th Mar 2021, 1:01 PM
Qusi AL-Hejazi
Qusi AL-Hejazi - avatar
- 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
27th Mar 2021, 2:22 PM
Abhishek Pandey
Abhishek Pandey - avatar