Skip to content

Instantly share code, notes, and snippets.

@tonkatsu7
Created July 10, 2018 05:24
Show Gist options
  • Save tonkatsu7/4180ef49c88f1e152866fd7c6e70cfac to your computer and use it in GitHub Desktop.
Save tonkatsu7/4180ef49c88f1e152866fd7c6e70cfac to your computer and use it in GitHub Desktop.
CoderByte challenge Letter Capitalise
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