Bonjour,
je dois à partir d'un fichier créer une matrice comme ceci :
Fichier :
Ce qui doit apparaitre à l'écran :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 8 5 10;8;15;17;18;20;15;15 10;17;18;10;13;14;5;5 13;2;1;4;6;6;4;0 0;5;0;4;4;4;4;5 10;14;17;17;15;16;16;15
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 10 8 15 17 18 20 15 15 10 17 18 10 13 14 5 5 13 2 1 4 6 6 4 0 0 5 0 4 4 4 4 5 10 14 17 17 15 16 16 15
Le problème c'est que j'ai l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 import java.util.*; import java.io.*; public class ProcessData { public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("ERREUR"); System.exit(1); } String filename = args[0]; Scanner scanner = null; try { scanner = new Scanner(new File(filename)); String ligne = scanner.nextLine(); int nbLignes = Integer.parseInt(ligne); ligne = scanner.nextLine(); int nbColonnes = Integer.parseInt(ligne); int[][] matrice = new int[nbLignes][nbColonnes]; for (int i = 0; i < nbLignes; i++) { ligne = scanner.nextLine(); String[] tokens = ligne.split(";"); for(int j = 0; j < nbColonnes; j++){ matrice[i][j] = Integer.parseInt(tokens[j]); } } for (int i = 0; i < nbLignes; i++) { for(int j = 0; j < nbColonnes; j++){ System.out.println(matrice[i][j]); } } } finally { if (scanner != null) { scanner.close(); } } } }
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Exercice6.ProcessData.main(ProcessData.java:41)
Et je ne sais pas dutout d'où ça peut venir !
Quelqu'un peut il m'aider?
Merci d'avance
Aurore
Partager