IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Java:sort donne erreur


Sujet :

avec Java

  1. #1
    Membre très actif
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Par défaut Java:sort donne erreur
    Bonjour,
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
    import javax.swing.*; 
    public class Extra_1  
    { 
      private static int user_feedback; 
    public static void main(String[]args) 
      { 
       String output="index\n"; 
       int array_first[]=length(); 
       int array_second[]=length(); 
       create_first(array_first); 
       create_second(array_second); 
       int added_array[]=new int[array_first.length+array_second.length]; 
       added(array_first,array_second,added_array); 
       sort(added_array);
     
       for(int counter=0;counter<added_array.length;counter++) 
        output+=added_array[counter]+"\n"; 
     
       print(output); 
      } 
     
     public static void create_first(int array1[]) 
        { 
         for(int counter=0;counter<array1.length;counter++) 
          array1[counter]=input(counter); 
        } 
        public static void create_second(int array3[]) 
        { 
         for(int counter=0;counter<array3.length;counter++) 
          array3[counter]=input(counter); 
        } 
        public static int[]length() 
        { 
         int user_feeback=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the length of array")); 
         return new int[user_feedback]; 
        } 
        public static int input(int number) 
        { 
         return number=Integer.parseInt(JOptionPane.showInputDialog(null, "Enter"+number+"the element of array")); 
     
        } 
        public static void added(int array_1[],int array_2[],int array_added[]) 
     
        { 
         int counter; 
         int count; 
         for(counter=0;counter<array_1.length;counter++) 
         { 
          array_added[counter]=array_1[counter]; 
          System.out.println(array_added[counter]); 
     
          for(count=0;count<array_2.length;count++) 
          { 
           array_added[count+array_1.length]=array_2[count]; 
           System.out.println(array_added[count+array_1.length]); 
          } 
         } 
     
         public static void sort(int sorting_array[]) 
         { 
          for(int pass=1;pass<sorting_array.length;pass++)//loop to control number of passes 
           for(int counter1=0;counter<sorting_array.length-1-(pass-1);counter++) 
     
           if(sorting_array[counter]>sorting_array[counter+1])//compare 
            swap(sorting_array,sorting_array[counter],sorting_array[counter+1]); 
         } 
        } 
        public static void swap(int swappingArray[],int number1,int number2) 
        { 
         int temp=number1; 
         number1=number2; 
         number2=temp; 
        } 
        public static void print(String element) 
        { 
         JTextArea outputArea=new JTextArea(); 
         outputArea.setText(element); 
         JOptionPane.showMessageDialog(null, outputArea,"Arrays",JOptionPane.INFORMATION_MESSAGE); 
        }   
        }
    j'ai erreur suivante:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method sort(int[]) is undefined for the type Extra_1
    at Extra_1.main(Extra_1.java:14)
    la lige 14 est:
    sort(added_array)
    pourtant la ligne qu'il est indiqué,je crois que j'ai écrit bien
    public static void sort(int sorting_array[])
    aidez moi svp

  2. #2
    Modérateur
    Avatar de XxArchangexX
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Mars 2012
    Messages
    1 159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 159
    Par défaut
    Bonjour,

    Si je lis bien ligne 45 tu ouvres une fonction added mais tu la refermes qu'après la fonction sort. Donc ligne 68 l'accolade place la à la ligne 59. l'appli devrait mieux detecter ta fonction.
    L'Etat est bien administré quand l'escalier de l'école est usé et que l'herbe croît sur celui du tribunal.

    Modérateur BI

  3. #3
    Membre très actif
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Par défaut
    ok,j'ai corrigé mon erreur
    et exécute le prg,ce dernier qui s'affiche
    1er dialogue box avec le titre "entrée,dans le quel indiqué
    "Enter the length of array",dans ce txt box, j'ajoute le chiffre 4 et clique sur ok
    etpuis une autre boite de dialogue apparait et je rentre le chiffre 2,et clique sur ok,maintenant j'ai encore une boite de dialogue avec le titre array,et dans le txt
    box apparait index,aidez moi svp

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Citation Envoyé par domxaline Voir le message
    ok,j'ai corrigé mon erreur
    et exécute le prg,ce dernier qui s'affiche
    1er dialogue box avec le titre "entrée,dans le quel indiqué
    "Enter the length of array",dans ce txt box, j'ajoute le chiffre 4 et clique sur ok
    etpuis une autre boite de dialogue apparait et je rentre le chiffre 2,et clique sur ok,maintenant j'ai encore une boite de dialogue avec le titre array,et dans le txt
    box apparait index,aidez moi svp
    Et c'est quoi le problème maintenant

  5. #5
    Membre très actif
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Par défaut
    pourquoi s'affiche une boite de dialogue avec un txt box contenant "index"
    avec un i dans un rond aussi

  6. #6
    Modérateur
    Avatar de XxArchangexX
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Mars 2012
    Messages
    1 159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 159
    Par défaut
    Tu as une fonction print ligne 79 avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    JOptionPane.showMessageDialog(null, outputArea,"Arrays",JOptionPane.INFORMATION_MESSAGE);
    c'est la fenêtre qui fait le i d'information dans un rond bleu. Tu fais un appel de cette fonction dans ton main.
    L'Etat est bien administré quand l'escalier de l'école est usé et que l'herbe croît sur celui du tribunal.

    Modérateur BI

  7. #7
    Membre très actif
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Par défaut
    bute de mon prg est:
    il faut assembler deux arrays dans un autre array et le trier (troisième array) par ordre de croissance;et faire apparaitre dans une boite de dialogue,
    mais dans le dernier boite de message ,au lieu d'apparaitre résultat trié,
    apparait "index" seulement,c'est pas normal,c'est pour ça je vous demande aide
    merci d'avance

  8. #8
    Candidat au Club
    Homme Profil pro
    Truc
    Inscrit en
    Mai 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Truc

    Informations forums :
    Inscription : Mai 2012
    Messages : 3
    Par défaut
    Bonjour,

    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    import javax.swing.JOptionPane;
    import javax.swing.JTextArea;
     
    public class Extra_1 {
    	private static int[] array1;
    	private static int[] array2;
    	private static int[] array3;
     
    	public static void main(String[] args) {
    		int array_first = length();
    		int array_second = length();
    		create_first(array_first);
    		create_second(array_second);
    		array3 = new int[array_first + array_second];
    		added(array1, array2, array3);
    		sort(array3);
     
    		StringBuffer output = new StringBuffer();
    		for (int counter = 0; counter < array3.length; counter++) {
    			output.append(array3[counter]);
    			output.append("\n");
    		}
     
    		print(output.toString());
    	}
     
    	public static void create_first(int array_first_length) {
    		array1 = new int[array_first_length];
    		for (int counter = 0; counter < array_first_length; counter++) {
    			array1[counter] = input(counter);
    		}
    	}
     
    	public static void create_second(int array_second_length) {
    		array2 = new int[array_second_length];
    		for (int counter = 0; counter < array_second_length; counter++) {
    			array2[counter] = input(counter);
    		}
    	}
     
    	public static int length() {
    		return Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the length of array"));
    	}
     
    	public static int input(int number) {
    		return Integer.parseInt(JOptionPane.showInputDialog(null, "Enter" + number + "the element of array"));
     
    	}
     
    	public static void added(int array_1[], int array_2[], int array_added[]) {
    		int totalCount = 0;
    		for (int counter = 0; counter < array_1.length; counter++) {
    			array_added[totalCount++] = array_1[counter];
    			System.out.println(array_added[totalCount - 1]);
    		}
    		for (int counter = 0; counter < array_2.length; counter++) {
    			array_added[totalCount++] = array_2[counter];
    			System.out.println(array_added[totalCount - 1]);
    		}
     
    	}
     
    	public static void sort(int sorting_array[]) {
    		for (int pass = 1; pass < sorting_array.length; pass++) {
    			// loop to control number of passes
    			for (int counter1 = 0; counter1 < sorting_array.length - 1 - (pass - 1); counter1++) {
     
    				if (sorting_array[counter1] > sorting_array[counter1 + 1])// compare
    					swap(sorting_array, counter1);
    			}
    		}
    	}
     
    	public static void swap(int swappingArray[], int number1) {
    		int temp = swappingArray[number1];
    		swappingArray[number1] = swappingArray[number1 + 1];
    		swappingArray[number1 + 1] = temp;
    	}
     
    	public static void print(String element) {
    		JTextArea outputArea = new JTextArea();
    		outputArea.setText(element);
    		JOptionPane.showMessageDialog(null, outputArea, "Arrays", JOptionPane.INFORMATION_MESSAGE);
    	}
    }
    Voilà un code "corrigé" sans effort car tu devrais quand même faire attention à ce que tu écris car ce n'est vraiment pas élégant.

    Cdlt,

    Alexandre

Discussions similaires

  1. creation de l'archive JAVA donne erreurs
    Par chapeau_melon dans le forum WinDev
    Réponses: 3
    Dernier message: 15/05/2008, 11h36
  2. [Java][Corba][Noob] Erreur a l'exécution
    Par GyZmoO dans le forum CORBA
    Réponses: 2
    Dernier message: 24/04/2007, 17h30
  3. [Java et Access] Erreur de syntaxe
    Par jgavard dans le forum JDBC
    Réponses: 7
    Dernier message: 10/12/2006, 16h03
  4. java.lang.NoSuchMethodError erreur java
    Par mistify dans le forum Langage
    Réponses: 7
    Dernier message: 24/10/2006, 16h06
  5. [vb.net][base de données]erreur
    Par Alex35 dans le forum Accès aux données
    Réponses: 4
    Dernier message: 16/11/2005, 11h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo