Last active
October 13, 2015 12:08
-
-
Save mtimkovich/4193572 to your computer and use it in GitHub Desktop.
Random Capitals program in Java
This file contains 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
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