Java - Write code to Return true if the given string starts with an uppercase letter.

Requirements

Write code to Return true if the given string starts with an uppercase letter.

Demo

/*
 * Copyright (c) 2001-2002, Marco Hunsicker. All rights reserved.
 *
 * This software is distributable under the BSD license. See the terms of the
 * BSD license in the documentation provided with this software.
 *//*from  w w w  .ja v a2s .  c o  m*/
 
//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(startsWithUppercase(str));
    }

    /**
     * Returns <code>true</code> if the given string starts with an uppercase letter.
     *
     * @param str string to check.
     *
     * @return <code>true</code> if the given string starts with an uppercase letter.
     */
    public static boolean startsWithUppercase(String str) {
        if (str.length() == 0) {
            return false;
        }

        return isUppercase(str.charAt(0));
    }

    /**
     * Returns <code>true</code> if the given letter is uppercase.
     *
     * @param letter letter to check for capitalization.
     *
     * @return <code>true</code> if the given letter is uppercase.
     */
    public static boolean isUppercase(char letter) {
        if ((letter < 'A') || (letter > 'Z')) {
            return false;
        }

        return true;
    }
}