/*
This program demonstrates how an array of strings can be created and used.
Note the difference between "declaration" and "creation" of an array.
Aditya Mathur. Feb 4, 2019

 */

import java.util.Scanner;

public class ArrayOfStrings {

    public static void main(String[] args) {
        String[] names; //Declare an array of Strings
        final int maxNames = 10; // Max size of the aray
        names = new String[maxNames]; // Create the array

        // Set up to read names from console, and then
        // read a line of names separated by a comma (nomber of names limited)
        Scanner s = new Scanner(System.in);
        System.out.print("Enter names separated by comma: ");
        String allNames = s.nextLine();

        // Split the string into an array of names
        names = allNames.split(","); // Separate the names.
        System.out.println("Names of people");
        int namesOutput=0;
        for (int n = 0; n < names.length; n++) {
            names[n] = names[n].replace(" ", "");
            if (names[n].length()!=0) {
                namesOutput++;
                System.out.println("\t" + namesOutput  + " " +  " "+names[n]);
            }
        }// End of for to print all names

        // Define an array using enumeration.
        String[] flowers = {"Rose", "Poinsettia", "Daisy"};
        System.out.println("Flowers");
        for (int n = 0; n < flowers.length; n++) {
            System.out.println("\t" + (n + 1) + " " + flowers[n]);
        }//

    }// End of main()
}// End of class.
