I have the following code that looks for me inside a table if the number entered by keyboard is inside it:
import java.util.*;
public class busquedaSecuencial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] numeros = {1, 3, 5, 7, 9};
int n, i = 0;
boolean encontrado = false;
System.out.println("\tPrograma que busque un numero en una lista");
System.out.print("Introduce el numero que deseas buscar: ");
n = sc.nextInt();
System.out.println("\n");
while ((i < numeros.length) && !encontrado) {
if (numeros[i++] == n) {
encontrado = true;
}
}
if (encontrado) {
System.out.println("El número " + n + " está en la lista");
} else {
System.out.println("El numero " + n + " no está en la lista\n");
}
}
}
The point is that I would like the table to be automatically filled with random values. Thank you very much for your help.
You can do this:
In this way you would randomly fill the positions of the array with numbers from 0 to 100. Give it a try and see how it goes for you.