
/*
	Tom DeDonno

	Demonstrates String Method:
	
		length, equal, charAt, indexOf, subString, compareTo
		
	Found on Page 82-85

 */

import java.lang.String;
public class MyString {

	public static void myPrint( String str ) {
          
               	String testStr = "Hello World";
		System.out.println( "The String is ->" + str + "<-" );
		System.out.println( "Length is:" +  str.length( ) );
		System.out.println( "First Character is:" + str.charAt(0) +
		" Second Character is: " + str.charAt(1) );

                System.out.println( "Index of flies = " + str.indexOf( "flies" )
                + " Index of Hello " + str.indexOf( "Hello" ) );
                
		System.out.print( "Is " );
		if( str.equals( testStr ) ) 
			System.out.print( "Equal " );
		else
			System.out.print( "Not Equal to " );
		System.out.println( testStr );

		System.out.println( "Second Half of String is->" +
		str.substring( str.length()/2  ) );

		String testStr1 = "ABC";
		String testStr2 = "abc";
                
                /* ASCII Chart
                
      0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
      0  NUL SOH STX ETX EOT ENQ ACK BEL BS  HT  LF  VT  FF  CR  SO  SI
1  DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM  SUB ESC FS  GS  RS  US
2   SP  !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
3   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
4   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
5   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _
6   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
7   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~ DEL
                 */


                System.out.println( "ASCII Order: 0,1..9,...A,B..Z,...a,b..z");
		System.out.print( "Compared to ->" + testStr1 +"<- String" +
		" is " + str.compareTo( testStr1 ) + " " );
                if( str.compareTo( testStr1 ) > 0 ) 
                  System.out.println( "Lexically Greater " );
                else
                  System.out.println( "Lexically Less" );
		System.out.println( "Compared to ->" + testStr2 + "<- String" +
		" is " + str.compareTo( testStr2 ) );
		System.out.println( "======================" );
		}// end print
	
	public static void main( String[] args ) {

		String greeting = "Hello";
		String sentence = greeting + " my friend";

		myPrint( sentence );
		                
                String java = "Java is fun.";
                myPrint( java );
                
                String phrase = "Time flies like an arrow.";
                myPrint( phrase );
                
		}
}


		
