2010-12-07 5 views
-3

j'ai ce code et je veux changer à BigIntegercomment puis-je utiliser BigInteger en java

import java.util.*; 
public class Euclid { 
    long TIME; 
    long start = System.currentTimeMillis(); 
    private static final String EXCEPTION_MSG = 
     "Invalid value (%d); only positive integers are allowed. "; 

    public static int getGcd(int a, int b) 

    {//long start = System.currentTimeMillis(); 
     if (a < 0) 
     { 
      throw new IllegalArgumentException(String.format(EXCEPTION_MSG, a)); 
     } 
     else 
      if (b < 0) 
      { 
       throw new IllegalArgumentException(String.format(EXCEPTION_MSG, b)); 
      } 

     while (b != 0) 
     {    
      if (a > b) 
      { 
       a = a - b; 
      }  
      else 
      { 
       b = b - a; 
      }  
     } 
     return a; 
     //long timeTaken = System.currentTimeMillis() - start; 
    } 
} 
+1

vous voulez changer 'start' à BigInteger de Long, droit ? –

Répondre

1
+0

pourriez-vous s'il vous plaît corriger mon code – user528644

+3

SO n'est pas un "programme de réparation gratuitement" service. Si vous êtes un étudiant, c'est VOTRE travail d'écrire et de corriger vos programmes. Si vous n'êtes pas un étudiant ... allez-y et engagez un programmeur professionnel. –

+0

Je suis désolé. L'exemple devrait vous donner une longueur d'avance sur l'utilisation de BigInteger. Vous pouvez google pour plus d'exemples. http://java2s.com/ ont une énorme quantité d'échantillons à utiliser en passant. – thotheolh