Contents

Capitalize (with.Java)

   Oct 13, 2023     1 min read

In this article, we learned how to capitalize.

We’ll do this by solving a coding test problem, reflecting on the problem we solved, and learning about other ways to solve it.

Let’s start with the problem

Problem

You are given a string, myString, consisting of the alphabet.

Complete a solution function that converts all the alphabets to uppercase and returns it.

Example input and output
myStringresult
“aBcDeFg”“ABCDEFG”
“AAA”“AAA”

My solution to the problem

class Solution {
    public String solution(String myString) {
        return myString.toUpperCase();
    }
}
Solution description

String solution(String myString) : Defines a function that takes a string as input.

return myString.toUpperCase();: Returns the result of converting the string myString to upper case.

This code accomplishes a simple task. It converts all the characters within the given string to uppercase and returns the result.