Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words.
Ex: If the input is:
4 hello zoo sleep drizzle z
then the output is:
zoo
drizzle
To achieve the above, first read the list into an array. Keep in mind that the character 'a' is not equal to the character 'A'.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
/* Type your code here. */
}
}
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String arr[] = new String[n]; for (int i = 0; i < n; i++) { arr[i] = scan.next(); } char ch = scan.next().charAt(0); for (int i = 0; i < arr.length; i++) { boolean found = false; for (int j = 0; j < arr[i].length(); j++) { if (arr[i].charAt(j) == ch) { found = true; break; } } if (found) { System.out.println(arr[i]); } } } }
Get Answers For Free
Most questions answered within 1 hours.