Skip to content
Snippets Groups Projects
Commit 450f277d authored by Hai Dang's avatar Hai Dang
Browse files

Updated Crossword

Valeur des variables rows et collums déterminé, construction d'un
tableau de dimension :rows*collums, utilisation du constructeur de
Crossword dans la class Main, enfin visualisation du tableau possible
grace a la méthode display. TACHE 1 FAIT.
parent 563dee9b
Branches
No related tags found
No related merge requests found
import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;
import java.io.*; import java.io.*;
...@@ -22,11 +23,33 @@ public class Crossword ...@@ -22,11 +23,33 @@ public class Crossword
** Updates <rows> and <columns> to height and width of the array. */ ** Updates <rows> and <columns> to height and width of the array. */
public Crossword(File file) throws IOException { public Crossword(File file) throws IOException {
if(!file.exists()){
System.out.println("le fichier n'existe pas");
return;
}
// Code pour calculer la taille du tableau et initialiser les variables d'instance "rows" et "columns" // Code pour calculer la taille du tableau et initialiser les variables d'instance "rows" et "columns"
Scanner scan = new Scanner(file);
columns = scan.next().length();
while (scan.hasNextLine()) {
rows++;
scan.nextLine();
}
// Code pour créer le tableau "array" // Code pour créer le tableau "array"
char[][] array = new char[rows][columns];
// Code pour remplir "array" avec les caractères du Fichier "file" // Code pour remplir "array" avec les caractères du Fichier "file"
Scanner scanner = new Scanner(file);
for (int i = 0; i < rows; i++) {
String fileLine = scanner.nextLine();
for (int j = 0; j < columns; j++) {
char nextChar = fileLine.charAt(j);
array[i][j] = nextChar;
}
}
this.array = array;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment