Java - Write code to Return true if the given string contains at least one uppercase letter.

Requirements

Write code to Return true if the given string contains at least one 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.j  a  v  a2  s .  c  o m
 
//package com.book2s;

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

    /**
     * Returns <code>true</code> if the given string contains at least one uppercase
     * letter.
     *
     * @param str string to check for uppercase letters.
     *
     * @return <code>true</code> if the given string contains at least one uppercase
     *         letter.
     */
    public static boolean containsUppercase(String str) {
        if (str.length() == 0) {
            return false;
        }

        for (int i = 0, size = str.length(); i < size; i++) {
            if (isUppercase(str.charAt(i))) {
                return true;
            }
        }

        return false;
    }

    /**
     * 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;
    }
}