2016-11-22 3 views
0

なぜこのコードの出力が0.0の10行だけで、どのように変更するのですか?あなたがres[idx]配列を初期化しているところ起動中スレッドを拡張することが正しく動作しないJavaテストでの簡単な演習

public class Staszeskitest extends Thread 
{ 

    static double res[] = new double[10]; 
    int idx; 

    Staszeskitest(int idx) 
    { 
     this.idx = idx; 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) 
    { 
     for(int i = 0; i < 10; i++) 
     { 
      new Staszeskitest(i).start(); 
      System.out.println(res[i]); 
     } 
    } 

    public void run() 
    { 
     res[idx] = 1; 
     for(int i = 0; i < 100; i++) 
     { 
      res[idx] -= (.01 * idx) * res[idx]; 
     } 
    } 

} 
+1

テストに合格すれば何が勝つのですか? –

+0

それは私のためではなく、それは追放されようとしている私の友人のためです – foxale

答えて

0
res[idx] -= (.01 * idx) * res[idx]; 

。この配列の各要素のデフォルト値は0.0で、上記のステートメントではres[idx](.01 * idx)を掛けているので、常に0.0が返されます。

関連する問題