Bonjour tout le monde !
je débute en JAVA ! et je veux faire des fonctions pour créer un tableau et le remplir aléatoirement , puis chercher un élément dans ce tableau !
voici le code que j'ai fait , mais qui ne marche toujours pas !
je vous serai très reconnaissante si quelqu'un pourrait me détecter les fautes !
Mercii
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
 
package hello;
import java.util.Scanner;
 
public class Tableau { 
	public static int[] Remplir(int len) {
		int[] tab = {} ;
		for(int i = 0 ; i<tab.length; i++){
			 tab[i] = 15+ (int) (Math.random()*60) ;
		    }
		return tab;
	     }
	public static boolean Rechercher (int x,int[] tab) {
		int a , i = 0 ;
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
			    System.out.println("Donner un entier ");
			    a = sc.nextInt() ;
                for (i=0 ; i<tab.length ; i++) {
                	if(tab[i]==a)
                		System.out.println(" L'entier " +a+ " se trouve  dans le tableau !");
			        else 
			        	System.out.println(" L'entier " +a+ " ne se trouve pas dans le tableau !");
                }
	}	
     public static void main(String [] args) {
	    int[] tab1 = null;
	    Remplir(10) ;
		Rechercher(5,tab1) ;
     }
}