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:Syntax error on token ";", . expected


Sujet :

avec Java

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

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut Java:Syntax error on token ";", . expected
    bonjour
    prg suivant me donne erreur
    Syntax error on token ";", . expected
    i cannot be resolved or is not a field
    at Fusionner.buildRandomSortedIntArray(Fusionner.java:32)
    at Fusionner.main(Fusionner.java:13)
    pourtant j'ai bien mis point virgule

    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
     
    import java.util.Arrays;
    import java.util.Random;
    public class Fusionner 
    {
       public static Random random=new Random(System.nanoTime());
       private static final int NB_OF_TEST=10;
       public static void main(String[]args)
       {
    	 int maxLength=1;
    	 for(int test=0;test<NB_OF_TEST;test++,maxLength*=2)
    	 {
    		 int[]increasing=buildRandomSortedIntArray(true,random.nextInt(maxLength));
    		 int[]decreasing=buildRandomSortedIntArray(false,random.nextInt(maxLength));
    		 System.out.println("_____________________________________________________");
    		 System.out.println("Croissant:"+Arrays.toString(increasing));
    		 System.out.println("Décroissant:"+Arrays.toString(decreasing));
    		 int[]merged=new int[increasing.length+decreasing.length];
    		 merge(increasing,decreasing,merged);
    		 System.out.println("Fusion:"+Arrays.toString(merged));
    	 } 
       }
       private static int[]buildRandomSortedIntArray(boolean increasing, int length)
       {
    	   int[]array=new int[length];
    	   for(int i=0;i<array.length;i++)
    		   array[i]=random.nextInt(10*length);
    	   Arrays.sort(array);
    	   if(!increasing)
    	   {
    		   int max=0;
    		   for(int i=0;max=array.length/2;i<max;i++)
    		   {
    			   int tmp=array[array.length-i-1];
    			   array[array.length-i-1]=array[i];
    			   array[i]=tmp;
    		   }
    	   }
    	   return array;
       }
       public static void merge(int[]increasing,int[]decreasing,int[]merged)
       {
    	   int leftIndex=0;
    	   int rightIndex=decreasing.length-1;
     
    	   int mergedIndex=0;
    	   while(leftIndex<increasing.length&&rightIndex>=0)
    	   {
    		   int leftValue=increasing[leftIndex];
    		   int rightValue=decreasing[rightIndex];
    		   if(leftValue<=rightValue)
    		   {
    			   merged[mergedIndex++]=leftValue;
    			   leftIndex++;
    		   }
    		   else
    		   {
    			   merged[mergedIndex++]=rightValue;
    			   rightIndex--;
    		   }
    	   }
    	   if(leftIndex<increasing.length)
    		   System.arraycopy(increasing, leftIndex, merged, mergedIndex, increasing.length-leftIndex);
    	   else
    		   while(rightIndex>=0)
    			   merged[mergedIndex++]=decreasing[rightIndex--];
       } 
     }
    la ligne 13 est :
    int[]decreasing=buildRandomSortedIntArray(false,random.nextInt(maxLength));
    la ligne 32 est :
    for(int i=0;max=array.length/2;i<max;i++)
    {
    merci d'avance

  2. #2
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2004
    Messages
    1 184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 184
    Points : 1 745
    Points
    1 745
    Par défaut
    Bonjour,

    ne prends que 3 arguments
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for(int i=0    ;     max=array.length/2    ;     i<max    ;    i++)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    int max=array.length/2;
    for(int i=0;   i<max    ;    i++)

  3. #3
    Modérateur
    Avatar de wax78
    Homme Profil pro
    Chef programmeur
    Inscrit en
    Août 2006
    Messages
    4 074
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Chef programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2006
    Messages : 4 074
    Points : 7 978
    Points
    7 978
    Par défaut
    Ou utiliser la , mais bon ca rends le code bizarre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for(int i=0, max=balbal/2;i<max;i++)
    qui n'est autre que l'equivalent de

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    int i=0, max=balbal/2;
    for(;i<max;i++)
    (Les "ça ne marche pas", même écrits sans faute(s), vous porteront discrédit ad vitam æternam et malheur pendant 7 ans)

    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut
    merci beaucoup ça marche

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur "Syntax error on token "(", new expected after this token"
    Par domxaline dans le forum Débuter avec Java
    Réponses: 3
    Dernier message: 20/02/2013, 15h40
  2. Réponses: 0
    Dernier message: 20/02/2010, 16h30
  3. Syntax error on token
    Par ourab dans le forum Débuter avec Java
    Réponses: 9
    Dernier message: 21/11/2009, 20h49
  4. "syntax error before '(' token " .. oO
    Par jbarreau-mainson dans le forum C
    Réponses: 3
    Dernier message: 08/04/2009, 11h21
  5. syntax error before '!' token
    Par titmael dans le forum C
    Réponses: 18
    Dernier message: 10/11/2006, 23h07

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