Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class tests{
- public static void main(String[] args) throws IOException {
- String[] array = { "pedro", "juan", "hector", "nessx" };
- String search = "hector";
- boolean existe = false;
- int cont = 0;
- for (int i = 0; i < array.length; i++) {
- String valorarray = array[i];
- cont++;
- if (search.equals(valorarray)) {
- existe = true;
- break;
- }
- }
- if (existe) {
- System.out.println("El string "+search+" existe en la posicion: "+cont);
- } else {
- System.out.println("el string no existe");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement