Cant seem to figure out why my array isnt outputting the correct value. The sum prints out as the first integer in the array. I wanted the sum of all the integers in the array. Any ideas what could be wrong? I attempted to convert the int to a string to be sent out.
//Add values of Integers
int i; int sum = 0;
for(i = 0; i < intarray.length; i++){
sum = sum + intarray[i];
}
String sumOut = Integer.toString(sum);
System.out.println( "to Client: " + sumOut);
toclient.writeBytes("Sum = " +sumOut+'\n');
String sumOut = ...and usesumwhen printing, thetoStringmethod is called implicitly anyway.System.out.println(sum);immediately after the for loop