I'm stuck with this homework thing trying to figure out what this java code is supposed to do and how to fix it. I've been working on this forever. I know programming but I'm not good with Java, and also it doesn't help that this code is not written correctly:
public String mystery(String num) {
if (num == null) {
return "N/A";
}
int len = num.length();
int c = 0;
char[] sb = new char[len];
for (int i = 0; i < len; i++) {
sb[c++] = num.charAt(i);
if ((len - 1 - i) % 3 == 0 && i != len - 1) {
sb[c++] = ',';
}
}
return new String(sb);
}
I know this may not be the best place to post this, but I'm not a part of any other forums really, nor do I know anyone who knows Java (with the exception of my sister's ex husband
)
Any help is greatly appreciated. Thank you.
public String mystery(String num) {
if (num == null) {
return "N/A";
}
int len = num.length();
int c = 0;
char[] sb = new char[len];
for (int i = 0; i < len; i++) {
sb[c++] = num.charAt(i);
if ((len - 1 - i) % 3 == 0 && i != len - 1) {
sb[c++] = ',';
}
}
return new String(sb);
}
I know this may not be the best place to post this, but I'm not a part of any other forums really, nor do I know anyone who knows Java (with the exception of my sister's ex husband

Any help is greatly appreciated. Thank you.