So I need to print an array of integers into a String, and I have it almost right with one problem
public static String arrayToString(int[] anArray) {
String x = "";
String y = "";
String result = "";
for (int i = 0; i < anArray.length; i++) {
y = Integer.toString(anArray[i]);
x = x + ", " + y;
}
result = "[" + x + "]";
return result;
}
public static void main(String[] args) {
int arrayInt[] = new int[] { 80, 100, 80, 92, 95, 87, 82, 76, 45, 76, 80, 70};
System.out.println("array : " + arrayToString(arrayInt));
}
When I execute the code, instead of printing:
[80, 100, 80, 92, 95, 87, 82, 76, 45, 76, 80, 70]
I get:
[, 80, 100, 80, 92, 95, 87, 82, 76, 45, 76, 80, 70]
This should be really simple to me but I'm stuck, where do I need to put an exception to remove it?