Break camelCase Challenge in Java

The challenge

Complete the solution so that the function will break up camel casing, using a space between words.

Example

solution("camelCasing") == "camel Casing"
Code language: Java (java)

Test cases

import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class SolutionTest { @Test public void tests() { assertEquals( "Incorrect", "camel Casing", Solution.camelCase("camelCasing")); assertEquals( "Incorrect", "camel Casing Test", Solution.camelCase("camelCasingTest")); assertEquals( "Incorrect", "camelcasingtest", Solution.camelCase("camelcasingtest")); } }
Code language: Java (java)

The solution in Java

class Solution { public static String camelCase(String input) { String out = ""; for (int i=0; i<input.length(); i++) { String c = Character.toString(input.charAt(i)); if (c.equals(c.toUpperCase())) { out+=" "; } out+=c; } return out; } }
Code language: Java (java)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments