pierre_1948
Messages postés2Date d'inscriptionjeudi 21 mai 2020StatutMembreDernière intervention21 mai 2020
-
Modifié le 31 juil. 2020 à 00:03
Twinuts
Messages postés5374Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention 3 mars 2023
-
17 août 2020 à 18:23
bonjour je suis debutant dans java
bon j'ai fait un exercice sur le tri a bulle et recherche dichotomique
mais ne marche pas
pierre me donner mon erreur et le code correcte
package numbers;
import java.util.Scanner ;
public class numbers {
private int tab[];
public numbers()
{
this.tab=new int[4] ;
}
public static void main(String[] args) {
numbers tab1 = new numbers() ;
tab1.tri() ;
tab1.length
tab1.recherchedicho(30, 0, tab1.length)
}
public void tri()
{
int aux=0 ;
for(int i=tab.length-1;0<=i;i++)
{
for(int j=0;j<i;j++)
{
boolean verif = true ;
if (tab [j]>tab[j+1])
{ aux=tab[j];
tab[j]=tab[j+1];
tab[j+1]=aux ;
verif = false ;
}
}
}
}
public boolean recherchedicho (int x ,int m ,int n )
{
boolean verif = false;
int a=m+n/2 ;
while ((verif != false) &&(m>0)&&(n<tab.length))
{
if (x==tab[a])
{
verif=true ;
return verif ;
}
else if (x<tab[a])
{
n=a ;
a=m+n/2 ;
}
else
{
m=a ;
a=m+n/2 ;
}
}
return verif ;
}
}
Twinuts
Messages postés5374Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention 3 mars 2023111 17 août 2020 à 18:23
Salut,
à la lecture de la fonction main, je doute que tu ailles jusqu'à l'étape de l’exécution...
public static void main(String[] args) {
numbers tab1 = new numbers() ;
tab1.tri() ;
tab1.length // <---- il manque le ';' de terminaison de plus il n'y a aucune variable length dans la classe numbers.
tab1.recherchedicho(30, 0, tab1.length) // <---- il manque le ';' de terminaison
}
dans la méthode 'tri', la variable 'verif' est inutile