/* Todays lecture started with a question from a student
    "How do we access an individual character from a string?"
*/

import java.util.Scanner;

class Jan30 {

	public static void main(String[] args) {

		Scanner kb = new Scanner(System.in);

		System.out.println("Please enter a string");

		// Whitespace consists of sp, \t (tab), \n (newline)

		// kb.nextLine() is a blocking method that returns a String
		// containing all of the characters that the user entered
		// before hitting the enter-key.

		// kb.next() is also blocking and returns when the user enters
		// the enter key, but the String returned is a token, a subset
		// of the characters entered by the user.

		// The Scanner by default, uses whitespace to separate 
		// tokens.  These separators are call delimiters.

		String input = kb.nextLine();

		// How to print individual characters?

		// Each character in a string has an index (int) associated
		// with it (starting at 0).

		// For example if the user entered "hello world" the indices
		// of the characters would be as follows.

		// h e l l o   w o r l d
		// 0 1 2 3 4 5 6 7 8 9 10

		// The string method charAt() takes an integer as an 
		// argument (an index) and returns the character in the string at
		// the specified index.

		char firstInitial = input.charAt(0);
		System.out.println("first: " + firstInitial);

        // We can print all of the characters and their index using
        // a while loop

		int i = 0;
		while(i < input.length()) {
			char c = input.charAt(i);
			System.out.printf("%d:%c\n", i, c);
			i++;
		}
		System.out.println();
	}
}
