Java
Résolu/Fermé
A voir également:
- Java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Waptrick jeux java itel ✓ - Forum Mobile
- Jeux java itel touche ✓ - Forum Logiciels
3 réponses
Arya Dröttningu
Messages postés
581
Date d'inscription
mardi 12 janvier 2010
Statut
Membre
Dernière intervention
3 janvier 2019
157
11 nov. 2010 à 20:05
11 nov. 2010 à 20:05
bonjour,
déjà renseigne toi sur comment fonctionne le tri par sélection (tu devrais trouver plein d'algo sur le net).
Ensuite il faut que tu apprennes les manipulations de fichier en java
déjà renseigne toi sur comment fonctionne le tri par sélection (tu devrais trouver plein d'algo sur le net).
Ensuite il faut que tu apprennes les manipulations de fichier en java
Arya Dröttningu
Messages postés
581
Date d'inscription
mardi 12 janvier 2010
Statut
Membre
Dernière intervention
3 janvier 2019
157
13 nov. 2010 à 14:34
13 nov. 2010 à 14:34
Essaye comme ça : par contre avant de le lancer supprime le fichier test.txt de ton ordi car là on ouvre le fichier en mode ajout ;)
package projet; import java.io.*; public class NewClass1 { public static void fichier (int taille, int d,int an) throws IOException { File fichier = new File("C:\\test.txt") ; BufferedWriter out = new BufferedWriter(new FileWriter(fichier, true)); String c = String.valueOf(d); String h = String.valueOf(an); String t = String.valueOf(taille); out.write(t+" "+c+" "+h); out.newLine(); out.close() ; } public static int[] tri(int [] T ,int taille) throws IOException { int inter; int c=0; int an =0; for(int h=0; h<taille; h=h+1) { for(int j=0; j<taille-h-1 ; j=j+1) { c++; if(T[j]>T[j+1]) { an++; inter=T[j]; T[j]=T[j+1]; T[j+1]=inter; } } } System.out.println("le nombre de comparaison" +" " + c); for(int f=0;f<taille;f++) { System.out.println(T[f]); } fichier (taille, c,an); return T ; } public static void main (String []args) throws IOException { int i; for(i=2;i<512;i++){ int [] T=new int [i]; tri(T,i); } } }
Arya Dröttningu
Messages postés
581
Date d'inscription
mardi 12 janvier 2010
Statut
Membre
Dernière intervention
3 janvier 2019
157
13 nov. 2010 à 14:57
13 nov. 2010 à 14:57
ben si tu veux que le tableau se remplisse d'éléments aléatoires faut le coder aussi !
Seul le main change (ici on suppose des nombres entre 0 et 200) :
Seul le main change (ici on suppose des nombres entre 0 et 200) :
public static void main (String []args) throws IOException { int i; int min = 0; int max = 200; for(i=2;i<512;i++){ int [] T=new int [i]; for (int j=0;j<T.length;j++) T[j] = (int)(Math.random() * (max-min)) + min; tri(T,i); } }
Arya Dröttningu
Messages postés
581
Date d'inscription
mardi 12 janvier 2010
Statut
Membre
Dernière intervention
3 janvier 2019
157
13 nov. 2010 à 15:18
13 nov. 2010 à 15:18
T'as pas trop cherché sur ce coup là :(
package projet; import java.io.*; /** * * @author Administrateur */ public class NewClass1 { public static void fichier (int taille, int d,int an) throws IOException { File fichier = new File("C:\\test.txt") ; BufferedWriter out = new BufferedWriter(new FileWriter(fichier, true)); String c = String.valueOf(d); String h = String.valueOf(an); String t = String.valueOf(taille); out.write(t+" "+c+" "+h); out.newLine(); out.close() ; } public static int[] tri(int [] T ,int taille) throws IOException { int inter; int c=0; int an =0; for(int h=0; h<taille; h=h+1) { for(int j=0; j<taille-h-1 ; j=j+1) { c++; if(T[j]>T[j+1]) { an++; inter=T[j]; T[j]=T[j+1]; T[j+1]=inter; } } } System.out.println("le nombre de comparaison" +" " + c); for(int f=0;f<taille;f++) { System.out.print(T[f]+" "); } System.out.print("\n"); fichier (taille, c,an); return T ; } public static void main (String []args) throws IOException { int i; int min = 0; int max = 200; for(i=2;i<512;i++){ int [] T=new int [i]; for (int j=0;j<T.length;j++) T[j] = (int)(Math.random() * (max-min)) + min; tri(T,i); } } }
11 nov. 2010 à 20:12
11 nov. 2010 à 20:17
11 nov. 2010 à 20:53
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projet;
import java.io.*;
/**
voici le code que je l utiliser mais il me dit apres l execution erreus
*
* @author Administrateur
*/
public class bulllllllllllllllle {
public static void main (String []args) throws IOException {
int [] T={18,15,11,1,5,6,13,9,7,4,24,5} ;
int n =T.length;
int [] A =tri(T,n);
public int[] tri(int [] T ,int taille)
{int f;
int inter;
int h;
int c=0;
int j;
for(h=0; h<taille; h=h+1){
for(j=0; j<taille-h-1 ; j=j+1){
c++;
if(T[j]>T[j+1])
{
inter=T[j];
T[j]=T[j+1];
T[j+1]=inter;
}
}
} System.out.println("le nombre de comparaison" +" " + c);
for( f=0;f<taille;f++){
System.out.println(T[f]);}return(T);
}
public static void fichier (int d) throws IOException{
File fichier = new File("c:\\fichier.txt") ;
PrintWriter out = new PrintWriter(new FileWriter(fichier)) ;
out.write("Comment allez vous") ;
out.write(d);
out.close() ;
}
}
11 nov. 2010 à 21:33
Tu ne dois pas déclarer de fonctions dans le main : il faut les déclarer juste avant.
Voilà normalement celui là compile :
Modifié par zmandarmarwa le 11/11/2010 à 22:48
je veux qu il créé un fichier automatique et mé dans eux le retour de la fonction
merci