2017-05-28 1 views
0

Mon code renvoie Runtime error, mais je ne sais pas comment résoudre ce problème. Ce code est sur le problème 104. J'ai essayé de changer quelque chose mais rien ... J'ai lu sur cette erreur et est fondamentalement associé au scanner. S'il vous plaît Aidez-moi!Erreur d'exécution UVA

import java.util.Scanner; 

public class Main { 

    static int MAX = 20; 
    static double LUCRO_MIN = 1.01; 

    public static void main(String[] args) { 
     Scanner sc = new Scanner (System.in); 
     int n, i, j; 
     double v; 
     while(sc.hasNext()) { 
      double[][] W = new double [MAX][MAX]; 
      n = sc.nextInt(); 
      sc.nextLine(); 
      for(i = 0; i < n; i++) { 
       int pos = 0; 
       String linha = sc.nextLine(); 
       String vertice[] = linha.split(" "); 
       for(j = 0; j < n; j++) { 
        if(i == j) { 
         W[i][i] = 0; 
         continue; 
        } 
        v = Double.parseDouble(vertice[pos]); 
        W[i][j] = v; 
        pos++; 
      } 
      } 
     Converte(n, W); 
     } 
    } 

    static public void Imprime (int i, int j, int l, int P[][][]) { 
     if(l == 0) 
     System.out.printf ("%d\n", i + 1); 
     else { 
     System.out.printf ("%d ", i + 1); 
     Imprime (P[l][i][j], j, l - 1, P); 
     } 
    } 

    static void IniZero (int n, double m[][][], int l) { 
     int i, j; 
     for(i = 0; i < n; i++) 
     for(j = 0; j < n; j++) 
      m[l][i][j] = 0; 
    } 

    static void Converte(int n, double W[][]) { 
     double[][][] B = new double [MAX][MAX][MAX]; 
     int [][][]P = new int [MAX][MAX][MAX]; 
     int l, i, j, k; 
     for(i = 0; i < n; i++) 
     for(j = 0; j < n; j++) { 
      B[1][i][j] = W[i][j]; 
      if(W[i][j] > 0) 
      P[1][i][j] = j; 
     } 
     for(l = 2; l <= n; l++) { 
     IniZero(n, B, l); 
     for(i = 0; i < n; i++) 
      for(j = 0; j < n; j++) 
      for(k = 0; k < n; k++) { 
       if(B[l][i][j] < W[i][k] * B[l - 1][k][j]) { 
       B[l][i][j] = W[i][k] * B[l - 1][k][j]; 
       P[l][i][j] = k; 
       if(B[l][i][i] >= LUCRO_MIN) { 
        Imprime(i, i, l, P); 
        return; 
       } 
       } 
      } 
     } 
     System.out.printf("no arbitrage sequence exists\n"); 
    } 
} 

Répondre

0

scanner changement comme celui-ci

Scanner input = new Scanner(System.in); 

À

Scanner input = new Scanner(new FileInputStream(args[0])); 

et je vous recommad à utiliser input.hasNext() au lieu de input.nextInt(); cela peut causer nullpointerexception

+0

je change mais don ne résoudrai pas mon problème. Erreur d'exécution – Juny