Javajava
javajava
-
leen.net Messages postés 247 Statut Membre -
leen.net Messages postés 247 Statut Membre -
Bonjour,
peut-on corriger ce code en java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.String;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
* @author samou7a
*/
public class fichier {
public static void decode(String [] tab)
{
int n=6;
String m=tab[0];
int f= Integer.parseInt(m);
int indice[]=new int[1000];
indice [0]=1;
// tableau de indice
for (int i=1;i<=f;i++){
int j =indice[i-1];
indice[i] =indice[i-1]+(2*Integer.parseInt(tab[j]))+1;
}
indice[f+1] = tab.length;
//affiche le tableau indice
for (int j=0;j<f;j++){
System.out.println(indice[j]);
}
//afficher le tableau entre les indice[i]+1 et indice[i+1]
for(int i = 0; i < indice.length; i++){
for (int k=indice[i]+1;k<indice[i+1];k++)
{
System.out.println(tab[k] );
}
}
// pour le matrice qui est extraire de premier tableau
int a=Integer.parseInt(m);
int[][] A = new int[n][a];
for (int j=0;j<n;j++){
for (int g=indice[j]+1;g<indice[j+1];g=g+2){
A[g][j]=Integer.parseInt(tab[g+1]);
}}
//affichage de matrice
for (int nc =1;nc< f;nc++)
{
for (int nl=1;nl<n;nl++)
{
System.out.println(A[nl][nc]);
}
}
}
//lire un fichier line par line ..
public static void affiche(String fichier) {
String filePath = "C:\\" + fichier + ".txt";
ArrayList<List<String>> matrix = new ArrayList<List<String>>();
try{
// Création du flux bufférisé sur un FileReader, immédiatement suivi par un
// try/finally, ce qui permet de ne fermer le flux QUE s'il le reader
// est correctement instancié (évite les NullPointerException)
BufferedReader buff = new BufferedReader(new FileReader(filePath));
try {
String line;
// Lecture du fichier ligne par ligne. Cette boucle se termine
// quand la méthode retourne la valeur null.
while ((line = buff.readLine()) != null) {
String[] nbs = line.split(" ");
//apelle de la methode decode
matrix.add(Arrays.asList(nbs));
}
//afficher les tableau
for (List<String> tab : matrix){
String[] tab1 = (String[]) tab.toArray();
System.out.println(tab);
decode( tab1);
}
} finally {
// dans tous les cas, on ferme nos flux
buff.close();
}
} catch (IOException ioe) {
// erreur de fermeture des flux
System.out.println("Erreur --" + ioe.toString());
}
}
// A chaque fois que tu veux recuper un element de new_tab, n'oublie pas de faire ceci:
// int exemple = Integer.ParseInt(new_tab[0]);
public static void main(String[] arg) throws IOException{
affiche("samiiha");
}
}
peut-on corriger ce code en java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.String;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
* @author samou7a
*/
public class fichier {
public static void decode(String [] tab)
{
int n=6;
String m=tab[0];
int f= Integer.parseInt(m);
int indice[]=new int[1000];
indice [0]=1;
// tableau de indice
for (int i=1;i<=f;i++){
int j =indice[i-1];
indice[i] =indice[i-1]+(2*Integer.parseInt(tab[j]))+1;
}
indice[f+1] = tab.length;
//affiche le tableau indice
for (int j=0;j<f;j++){
System.out.println(indice[j]);
}
//afficher le tableau entre les indice[i]+1 et indice[i+1]
for(int i = 0; i < indice.length; i++){
for (int k=indice[i]+1;k<indice[i+1];k++)
{
System.out.println(tab[k] );
}
}
// pour le matrice qui est extraire de premier tableau
int a=Integer.parseInt(m);
int[][] A = new int[n][a];
for (int j=0;j<n;j++){
for (int g=indice[j]+1;g<indice[j+1];g=g+2){
A[g][j]=Integer.parseInt(tab[g+1]);
}}
//affichage de matrice
for (int nc =1;nc< f;nc++)
{
for (int nl=1;nl<n;nl++)
{
System.out.println(A[nl][nc]);
}
}
}
//lire un fichier line par line ..
public static void affiche(String fichier) {
String filePath = "C:\\" + fichier + ".txt";
ArrayList<List<String>> matrix = new ArrayList<List<String>>();
try{
// Création du flux bufférisé sur un FileReader, immédiatement suivi par un
// try/finally, ce qui permet de ne fermer le flux QUE s'il le reader
// est correctement instancié (évite les NullPointerException)
BufferedReader buff = new BufferedReader(new FileReader(filePath));
try {
String line;
// Lecture du fichier ligne par ligne. Cette boucle se termine
// quand la méthode retourne la valeur null.
while ((line = buff.readLine()) != null) {
String[] nbs = line.split(" ");
//apelle de la methode decode
matrix.add(Arrays.asList(nbs));
}
//afficher les tableau
for (List<String> tab : matrix){
String[] tab1 = (String[]) tab.toArray();
System.out.println(tab);
decode( tab1);
}
} finally {
// dans tous les cas, on ferme nos flux
buff.close();
}
} catch (IOException ioe) {
// erreur de fermeture des flux
System.out.println("Erreur --" + ioe.toString());
}
}
// A chaque fois que tu veux recuper un element de new_tab, n'oublie pas de faire ceci:
// int exemple = Integer.ParseInt(new_tab[0]);
public static void main(String[] arg) throws IOException{
affiche("samiiha");
}
}