sábado, 25 de febrero de 2023

Búsqueda secuencial

 

package operadores;

import javax.swing.JOptionPane;

public class persona {

public static void main(String[] args) {

int arreglo[] = {4, 1, 2, 5, 3};

int dato;

boolean band = false;

dato = Integer.parseInt(JOptionPane.showInputDialog("Numero a buscar: "));

int i = 0;

while (i < 5 && band == false) {

if (arreglo[i] == dato) {

band = true;

}

i++;

}

if (band == false) {

JOptionPane.showMessageDialog(null, "No esta");

} else {

JOptionPane.showMessageDialog(null, "Esta en la posición " + (i));

}

}

}

No hay comentarios:

Publicar un comentario