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
la ligne 13 est :
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--]; } }
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
Partager