Capitalize Words in a Sentence with Loop
From Java Example Source Code
Contents |
[edit] Overview - Capitalize Words in a Sentence with Loop
This is a example of Java program.
[edit] Java Source Code
- Package: example.chartext
- File: Main.java
package example.chartext; public class Main { public static void main(String[] a) { String sentence = "this is a test"; String tmp = ""; String[] words = sentence.split(" "); for (int i = 0; i < words.length; i++) { tmp += words[i].substring(0, 1).toUpperCase(); tmp += words[i].substring(1).toLowerCase(); tmp += " "; } System.out.println(tmp.trim()); } }
[edit] What Result You Can Get
Run the program, you will get:
This Is A Test
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
