I have this code:
static String format(String number, int decimalLength) {
char[] decimal;
System.out.println(number);
String[] formatA = number.split(".");
System.out.println(formatA.length);
StringBuilder cents = new StringBuilder("");
int dollars = 0;
dollars = Integer.parseInt(formatA[0]);
decimal = formatA[1].toCharArray();
for (int i = 0; i < decimal.length; i++) {
if (i < decimalLength) {
cents.append(decimal[i]);
}
}
String moneyString = "$" + dollars + "." + cents;
return moneyString;
}
It looks fine to me, and yet this is the output I get:
323.90905
Error Output: java.lang.ArrayIndexOutOfBoundsException: 0
0
BUILD SUCCESSFUL (total time: 0 seconds)
Note: the line "Error output" is from an exception handler I created, the rest is coming from print statements within this method