Looking at this code:
if(strTemp.length() > maxWordLen) maxWordLen = strTemp.length();
This could be reduced to:
maxWordLen = Math.max(maxWordLen,strTemp.length());
Inline the incrementation:
charArr[i][j++] = ch;
Or just use System.arraycopy:
char[][] charArr = new char[strArr.length][maxWordLen];
for (int i = 0; i < strArr.length; i++) {
System.arraycopy(strArr[i].toCharArray(), 0, charArr[i], 0, strArr[i].length());
}
Either inline the output:
System.out.print((i != 0 ? " " : "") + charArr[i][j]);
or at least place braces:
if (i!=0){ System.out.print(" "); }
4 . If you wonder about other solutions, check this one:
int i = 0;
boolean hasMoreChars = true;
while (hasMoreChars) {
hasMoreChars = false;
for (String str : strArr) {
if (i < str.length()) {
hasMoreChars = true;
System.out.print(str.charAt(i) + " ");
}
else {
//two spaces, added by xploreraj in Edit
//in case a shorter word comes before longer word
//we must compensate the absence of character with space
System.out.print(" ");
}
}
System.out.println();
i++;
}