Write a JAVA Program that would: Allow user to enter the size and element of a string array. Then ask the user to give a string and display whether that string is present in array or not. (Letter case doesn’t matter)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the array size:");
String[] array = new String[Integer.parseInt(in.nextLine())];
System.out.println("Enter strings:");
for (int i = 0; i < array.length; i++) {
array[i] = in.nextLine();
}
System.out.println("Enter the string:");
String toFind = in.nextLine();
for (int i = 0; i < array.length; i++) {
if (array[i].equalsIgnoreCase(toFind)) {
System.out.println("The string is present in the array.");
return;
}
}
System.out.println("The string is not present in the array.");
}
}
Comments
Leave a comment