Capitalize in Java

Published on 28 April 2022 (Updated: 18 September 2022)

Capitalize in Java

Welcome to the Capitalize in Java page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

public class Capitalize
{

    public static boolean isLetter(char someChar)
    {
        return (someChar >= 'a' && someChar <= 'z') || (someChar >= 'A' && someChar <= 'Z');
    }

    public static boolean isUpperCase(char someChar)
    {
        return (someChar >= 'A' && someChar <= 'Z');
    }

    public static void main(String[] args)
    {
        if (args.length == 0 || args[0].equals(""))
        {
            System.out.println("Usage: please provide a string");
            System.exit(1);
        }
        String sentence = args[0];

        char firstChar = sentence.charAt(0);
        if (isLetter(firstChar) && !isUpperCase(firstChar))
        {
            char[] charArray = sentence.toCharArray();
            charArray[0] = Character.toUpperCase(firstChar);
            sentence = new String(charArray);
        }
        System.out.println(sentence);

    }
}

Capitalize in Java was written by:

If you see anything you'd like to change or update, please consider contributing.

Note: The solution shown above is the current solution in the Sample Programs repository as of Oct 26 2019 19:46:40. The solution was first committed on Oct 11 2019 21:27:34. As a result, documentation below may be outdated.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.