In JAVA:
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
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 scnr = new Scanner(System.in); int n = scnr.nextInt(); String[] words = new String[n]; for (int i = 0; i < words.length; i++) { words[i] = scnr.next(); } char ch = scnr.next().charAt(0); for (int i = 0; i < words.length; i++) { boolean found = false; for (int j = 0; j < words[i].length(); j++) { if (words[i].charAt(j) == ch) { found = true; } } if (found) { System.out.println(words[i]); } } } }
Get Answers For Free
Most questions answered within 1 hours.