Thursday, 4 December 2014

// The "StringMethodsExample10" class.  Page 358 (middle).
// (from the Carter book)
// Example 10.
//
// If String "alpha" has the value "abc", then the expression
// "alpha.toUpperCase().charAt(1)" will be evaluated, as follows:

public class StringMethodsExample10
{
    public static void main (String[] args)
    {
        String alpha = "abc";
        System.out.println (alpha.toUpperCase ());    // returns the value "ABC"
        System.out.println ("ABC".charAt (1));
        System.out.println (alpha.charAt (1));  // returns the value 'B'
        System.out.println (alpha.toUpperCase ().charAt (1)); // return the value 'B'
        // Note that these operations do NOT change the value of
        // String "s".

    } // main method
} // StringMethodsExample10 class

No comments:

Post a Comment