2017-03-08 8 views
1

リニア整数配列のインクリメントを増やすためにinterval parse intを実装する方法を教えてください。 もがJava実装のインターバル解析int

public class Sequence { 
    /*Generate an array representing a linear sequence of N values specified by the start value and the interval example,interval(6, 2, 3) would produce {2,5,8,11,14,17}*/ 
    public int[] Linear(int N, int start, int interval){ 
     int interval = Integer.parseInt(args[0]); 
     for (int i = 1; i<= N; i++); 
     i = i + interval; 


    } 

    //Generate an array of the first N values of the Fibonacci sequence (1,1,2,3,5,8,13,21,...). Assume N > 2 
    public static int[] fibonacci(int N){ 
     int[] fibo = new int [N + 1]; 
     fibo[0] = 1; 
     fibo[1] = 1; 
     for (int i = 2; i<= N; i++) 
      fibo[i]= fibo[i-1] + fibo[i-2]; 
     // int[] x = fibo; 
     return fibo; 

    } 

    public static void main(String[] args) { 

     int N = Integer.parseInt(args[0]);  
     //fibonacci(N); 



     for (int i = 1; i <= N; i++) 

      System.out.println(fibonacci(i)); 


    } 
} 
+1

? – LppEdd

答えて

1

それを返すこれはあなたのLinear方法は次のようになります方法です:リニア方式に[0]引数を使用しながら、それはどのようにコンパイルすることができ

public int[] Linear(int N, int start, int interval){ 

    // First declare the array. 
    int[] linearArray = new int[N]; 

    // Declare something to hold the next value 
    // The first value will be "start" 

    int value = start; 

    // Then, iterate over a for loop 
    for (int i = 0; i< N; i++){ 
     // assign the current value to the current indexed element in the array 
     linearArray[i] = value; 

     // compute next value 
     value = value + interval; 
    } 

    // Finally, return your array 
    return linearArray; 
}