char key = kpd.getKey();
...
key2 = (key2*10)+key[i];
key is declared as a single char, as is key2, not an array. Leaving that aside, key will have the ASCII value of the key pressed, not the actual (numeric) value. Subtract '0' from it if it is a number to get the actual number of the key pressed but you cannot then put it in key2 as currently declared.