You are on page 1of 2

package array;

import java.util.Scanner;

public class arrayactivity{

public static void main(String[] args){

Scanner sc=new Scanner(System.in);

String choice = "y";

while (choice.equalsIgnoreCase("y")) {

int n;

System.out.print("Enter the number of elements you want to store: ");


n=sc.nextInt();

sc.nextLine();

String[] arr = new String[n];

System.out.println("Enter the elements of the array: ");

for(int i=0; i<n; i++){

arr[i]=sc.nextLine();

System.out.println("Array elements are: ");

for (int i=0; i<n; i++){

System.out.println(arr[i]);

System.out.print("Enter a name to search for: ");

String searchName = sc.nextLine();

boolean found = false;

for (int i = 0; i<n; i++){

if (arr[i].equalsIgnoreCase(searchName)) {

System.out.println (searchName + " is found at index " + i);

found = true;

break;

if (!found) {

System.out.println(searchName + " not found in the array");

System.out.print("Do you want to continue? (Y/N): ");

choice = sc.nextLine();

You might also like