Answer to Question #161647 in Java | JSP | JSF for aj

Question #161647

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)


1
Expert's answer
2021-02-06T00:58:49-0500
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.");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog