[Solved] How to store each word from a scanner to an array


If I understand your question correctly, this is that I would do

Scanner keyb = new Scanner(System.in);
System.out.print("Enter a sentence: ");
String input = keyb.nextLine();
String[] stringArray = input.split(",");

To see the results:

for(int i=0; i < stringArray.length; i++){
    System.out.println(i + ": "  + stringArray[i]);
}

This will work for any size sentence as long as each word is separated by a ,.

0

solved How to store each word from a scanner to an array