Skip to content

Instantly share code, notes, and snippets.

@mtimkovich
Last active October 13, 2015 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtimkovich/4193572 to your computer and use it in GitHub Desktop.
Save mtimkovich/4193572 to your computer and use it in GitHub Desktop.
Random Capitals program in Java
public class randomCapitals {
public static String randomUpper(String sentence) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < sentence.length(); i++) {
char c = sentence.charAt(i);
if (Math.random() > .5) {
c = Character.toUpperCase(c);
} else {
c = Character.toLowerCase(c);
}
output.append(c);
}
return output.toString();
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.print(randomUpper(args[i]) + " ");
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment