Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

using for loop to search for an input java

import java.util.Scanner;

public class Sample {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String names[] = { "Jasmine", "Lyka", "Marbie", "Efren", "Tiny", "Soleen" };
        System.out.print("Enter a name to search:");
        String search = input.nextLine();
        for (int i = 0; i < names.length; i++) {
            if (names[i].equalsIgnoreCase(search)) {
                System.out.println("We found " + names[i]);
                break;
            }
        }
        input.close();
    }
}
 
PREVIOUS NEXT
Tagged: #loop #search #input #java
ADD COMMENT
Topic
Name
9+3 =