51 lines
1.0 KiB
Java
51 lines
1.0 KiB
Java
|
/* Joseph Green
|
||
|
* 7-Oct-2020
|
||
|
*
|
||
|
* take int for number of words
|
||
|
* take list of words
|
||
|
* take a char
|
||
|
*
|
||
|
* print out every word in the list that contains the char at least once
|
||
|
* Assume at least one word will contain the given char
|
||
|
* words will be < 20
|
||
|
*/
|
||
|
|
||
|
import java.util.Scanner;
|
||
|
|
||
|
public class LabProgram {
|
||
|
public static void main(String[] args) {
|
||
|
/* Type your code here. */
|
||
|
int numWords;
|
||
|
char someChar;
|
||
|
Scanner scnr = new Scanner(System.in);
|
||
|
|
||
|
String[] words = new String[20];
|
||
|
|
||
|
numWords = scnr.nextInt();
|
||
|
|
||
|
for (int i = 0; i<numWords; i++){
|
||
|
words[i] = scnr.next();
|
||
|
}
|
||
|
|
||
|
someChar = scnr.next().charAt(0);
|
||
|
|
||
|
for (int j = 0; j<numWords;j++){
|
||
|
for (int i = 0; i<words[j].length();i++){
|
||
|
if (someChar == words[j].charAt(i)){
|
||
|
System.out.println(words[j]);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
/* for (String word : words){
|
||
|
for (int i = 0; i<word.length();i++){
|
||
|
if (someChar == word.charAt(i)){
|
||
|
System.out.println(word);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}*/
|
||
|
}
|
||
|
}
|
||
|
|