The user is supposed to enter multiple words (without regards to lower/uppercase) with space inbetween, this text will then be translated into initials without any spaces included. However, I only want the initials of the words that I approve of, if anything but those words, the printout will instead say "?" instead of printing the first alphabet of a word. E.q: "hello hello hello" will come out as: "HHH", but "hello hi hello" or "hello . hello" will instead result in "H?H".
I've managed to make it print out the initials without the spaces. But I can't figure out how to add a condition where the program would first check whether the input contains unapproved words or signs/symbol or not in order to replace that unapproved or non-word with a question mark instead of just going ahead and printing the initial/sign. I've tried placing the for-loop inside an if-else-loop and using a switch()-loop but they won't interact with the for-loop correctly.
public static void main (String []args) {
Scanner keyboard = new Scanner (System.in);
System.out.println("Enter your words: ");
String input = keyboard.nextLine().toUpperCase();
String str = input;
String[] parts = str.split(" ");
System.out.print("The initials: ");
for (String i : parts) {
System.out.print(i.charAt(0));
}
}
So what happens right now is that regardless what words the user enter, the initials of each word or symbol/sign will be printed regardless.