有一列数,1.2.2.4.4.8.8.16.16.。。N   ,求第N个值。编写程序实现该算法

解决方案 »

  1.   

    第N个数是:2的 (N / 2)次方。(N / 2)是整数。
      

  2.   

    放在数组里
    设数组下标为i
    如果i为偶数
    所求数为2的i/2次方
    否则 如果i为奇数
    所求数为2的(i+1)/2次方
      

  3.   


    for(int i=0;i<num/2;i++){
       System.out.println(Math.pow(2, i));
          if(i==0)
    continue;
       System.out.println(Math.pow(2, i));
    }
      

  4.   

    public class TTe {
    public static void main(String[] args) {
    int[] a = new int[10];
    a[0] = 1;
    for (int i = 1; i < a.length; i++) {
    if (i % 2 == 0) {
    a[i] = a[i - 2] * 2;
    } else {
    a[i] = a[i - 1] * 2;
    }
    }
    for (int j = 0; j < a.length; j++) {
    System.out.println(a[j]);
    }
    }
    }
      

  5.   

    嗯 其实不用什么放数组里
    public static int get(int n) {
    int m = 1;
    for (int i = 0; i < n / 2; i++) {
    m *= 2;
    }
    return m;
    } public static void main(String[] args) {
    for (int i = 1; i < 20; i++) {
    System.out.print(get(i)+" ");
    }
    }