Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class tests{
  4.    
  5.     public static void main(String[] args) throws IOException {
  6.      
  7.       String[] array = { "pedro", "juan", "hector", "nessx" };
  8.       String search = "hector";
  9.       boolean existe = false;
  10.       int cont = 0;
  11.       for (int i = 0; i < array.length; i++) {
  12.          String valorarray = array[i];
  13.          cont++;
  14.          if (search.equals(valorarray)) {
  15.             existe = true;
  16.             break;
  17.          }
  18.       }
  19.       if (existe) {
  20.          System.out.println("El string "+search+" existe en la posicion: "+cont);
  21.       } else {
  22.       System.out.println("el string no existe");
  23.       }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement