In codewars I have completed a kata using for loop with 15 lines of code, some other person has completed it with just 7 lines. Could anybody explain the code?
public class CamelCase { public static String cAmEl(final String yourName) { final int length = yourName.length(); final StringBuilder cAmEl = new StringBuilder(length); boolean upper = true; for (int i = 0; i < length; i++, upper ^= true) { final char c = yourName.charAt(i); cAmEl.append(upper ? toUpperCase(c) : toLowerCase(c)); } return cAmEl.toString(); } } The code converts every alternate character of a string to uppercase (starting with an uppercase character). For example: test becomes TeSt.
I am unable to understand this part
cAmEl.append(upper ? toUpperCase(c) : toLowerCase(c));