Created
July 10, 2018 05:24
-
-
Save tonkatsu7/4180ef49c88f1e152866fd7c6e70cfac to your computer and use it in GitHub Desktop.
CoderByte challenge Letter Capitalise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
class Main { | |
public static String LetterCapitalize(String str) { | |
String[] words = str.split(" "); | |
StringBuilder sb = new StringBuilder(); | |
for (String word : words) { // for each word | |
if (Character.isLowerCase(word.charAt(0))) {// if first char is lower case | |
char[] chars = word.toCharArray(); | |
chars[0] = Character.toUpperCase(chars[0]); | |
sb.append(new String(chars)); | |
} else { | |
sb.append(word); | |
} | |
sb.append(" "); | |
} | |
return sb.toString().trim(); | |
} | |
public static void main (String[] args) { | |
// keep this function call here | |
Scanner s = new Scanner(System.in); | |
System.out.print(LetterCapitalize(s.nextLine())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment