I see you use a long var type (which is an integer number) as result of a division that results in a real number, counting on internal casting, I suppose.
Read here for a similar thread.
Just floor the division to obtain the integer part of it or change the var type of k to a real type.
Edit: AFAIK, that java error means that while converting a "string" to a number, the content of the string doesn't match with the expected number format (e.g. "12.5" can't match an integer).