upper and lower case
Converting your Java strings of text to upper or lower case is fairly straightforward: just use the inbuilt methods toUpperCase and toLowerCase.Start a new project for this, and add the following code:
result = changeCase.toUpperCase( );
To use a string method you first type the string you want to work on. For us,
this was the string in the variable called changeCase. Type a dot after
the variable name and you'll see a list of available methods that you can use
on your string. Select toUpperCase. (The method needs the empty round
brackets after it.)After Java has changed the word to uppercase letters, we're storing the new string into our result variable.
When the programme is run, the Output window displays the following:
System.out.println( changeCase.toUpperCase( ) );
Here, Java will just get on with converting the string, without needing to
assign the result to a new variable.If you want to convert to lowercase, just use the toLowerCase method instead. It is used in exactly the same way as toUpperCase.
In the next part, you'll see how to compare strings in Java
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment