2016-10-28 8 views
0

私のコードは、非常に大きな数に13個の隣接する数字の最大の製品を見つけることを意図しているが、何らかの理由で、それはあなたがにyとリセット6429780.キャッピングのBigInteger番号は

public class Euler8 { 
    public static void main(String[]args) { 
     String number=//large 1000 digit number 
     BigInteger[] anarray=new BigInteger[13]; 
     BigInteger product=new BigInteger("1"); 
     BigInteger maxproduct=new BigInteger("0"); 
     int y=0; 

     for(int i=0;i<number.length();i++){ 
      anarray[y]=BigInteger.valueOf(Long.valueOf(Character.toString(number.charAt(i)))); 
      y++; 
      if(i>=12){ 
       for(BigInteger x : anarray) { 
        if(x.compareTo(BigInteger.ZERO)==0||x.compareTo(BigInteger.ZERO)==1) { 
        product = product.multiply(x); 
        } 
       } 
       if(product.compareTo(maxproduct)==1){ 
        maxproduct=product;` 

       } 
       y=0; 
       product=BigInteger.ONE; 
      } 
     } 
     System.out.println(maxproduct); 
    } 
} 
+1

あなたの質問は何ですか? – kaitoy

答えて

0

でのBigInteger「製品を」キャッピングされましたループの各反復の後で0になるので、最初の13個の数値を加えた後で初めて配列の最初の要素を置き換えます。

+0

ありがとう、私はそれをキャッチしていないと信じて –

関連する問題